interface-ip.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * netifd - network interface daemon
  3. * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __INTERFACE_IP_H
  15. #define __INTERFACE_IP_H
  16. #include "interface.h"
  17. enum device_addr_flags {
  18. /* address family for routes and addresses */
  19. DEVADDR_INET4 = (0 << 0),
  20. DEVADDR_INET6 = (1 << 0),
  21. DEVADDR_FAMILY = DEVADDR_INET4 | DEVADDR_INET6,
  22. /* externally added address */
  23. DEVADDR_EXTERNAL = (1 << 2),
  24. /* route overrides the default interface metric */
  25. DEVROUTE_METRIC = (1 << 3),
  26. /* route overrides the default interface mtu */
  27. DEVROUTE_MTU = (1 << 4),
  28. /* route overrides the default proto type */
  29. DEVROUTE_PROTO = (1 << 5),
  30. /* address is off-link (no subnet-route) */
  31. DEVADDR_OFFLINK = (1 << 6),
  32. /* route resides in different table */
  33. DEVROUTE_TABLE = (1 << 7),
  34. /* route resides in default source-route table */
  35. DEVROUTE_SRCTABLE = (1 << 8),
  36. /* route is on-link */
  37. DEVROUTE_ONLINK = (1 << 9),
  38. /* route overrides the default route type */
  39. DEVROUTE_TYPE = (1 << 10),
  40. };
  41. union if_addr {
  42. struct in_addr in;
  43. struct in6_addr in6;
  44. };
  45. struct device_prefix_assignment {
  46. struct list_head head;
  47. int32_t assigned;
  48. uint8_t length;
  49. int weight;
  50. struct in6_addr addr;
  51. bool enabled;
  52. char name[];
  53. };
  54. struct device_prefix {
  55. struct vlist_node node;
  56. struct list_head head;
  57. struct list_head assignments;
  58. struct interface *iface;
  59. time_t valid_until;
  60. time_t preferred_until;
  61. struct in6_addr excl_addr;
  62. uint8_t excl_length;
  63. struct in6_addr addr;
  64. uint8_t length;
  65. char pclass[];
  66. };
  67. struct device_route {
  68. struct vlist_node node;
  69. struct interface *iface;
  70. bool enabled;
  71. bool keep;
  72. bool failed;
  73. union if_addr nexthop;
  74. int mtu;
  75. unsigned int type;
  76. unsigned int proto;
  77. time_t valid_until;
  78. /* must be last */
  79. enum device_addr_flags flags;
  80. int metric; /* there can be multiple routes to the same target */
  81. unsigned int table;
  82. unsigned int mask;
  83. unsigned int sourcemask;
  84. union if_addr addr;
  85. union if_addr source;
  86. };
  87. struct device_addr {
  88. struct vlist_node node;
  89. bool enabled;
  90. bool failed;
  91. unsigned int policy_table;
  92. struct device_route subnet;
  93. /* ipv4 only */
  94. uint32_t broadcast;
  95. uint32_t point_to_point;
  96. /* ipv6 only */
  97. time_t valid_until;
  98. time_t preferred_until;
  99. char *pclass;
  100. /* must be last */
  101. enum device_addr_flags flags;
  102. unsigned int mask;
  103. union if_addr addr;
  104. };
  105. struct device_source_table {
  106. struct list_head head;
  107. uint32_t table;
  108. uint16_t refcount;
  109. uint8_t v6;
  110. uint8_t mask;
  111. union if_addr addr;
  112. };
  113. struct dns_server {
  114. struct vlist_simple_node node;
  115. int af;
  116. union if_addr addr;
  117. };
  118. struct dns_search_domain {
  119. struct vlist_simple_node node;
  120. char name[];
  121. };
  122. extern const struct uci_blob_param_list route_attr_list;
  123. extern struct list_head prefixes;
  124. void interface_ip_init(struct interface *iface);
  125. void interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list);
  126. void interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list);
  127. void interface_write_resolv_conf(void);
  128. void interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6);
  129. void interface_ip_update_start(struct interface_ip_settings *ip);
  130. void interface_ip_update_complete(struct interface_ip_settings *ip);
  131. void interface_ip_flush(struct interface_ip_settings *ip);
  132. void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled);
  133. void interface_ip_update_metric(struct interface_ip_settings *ip, int metric);
  134. struct interface *interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface);
  135. struct device_prefix* interface_ip_add_device_prefix(struct interface *iface,
  136. struct in6_addr *addr, uint8_t length, time_t valid_until, time_t preferred_until,
  137. struct in6_addr *excl_addr, uint8_t excl_length, const char *pclass);
  138. void interface_ip_set_ula_prefix(const char *prefix);
  139. void interface_refresh_assignments(bool hint);
  140. #endif