2
0

interface-ip.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /* neighbor mac address */
  41. DEVNEIGH_MAC = (1 << 11),
  42. /* route specifies no device */
  43. DEVROUTE_NODEV = (1 << 12),
  44. };
  45. union if_addr {
  46. struct in_addr in;
  47. struct in6_addr in6;
  48. };
  49. struct device_prefix_assignment {
  50. struct list_head head;
  51. int32_t assigned;
  52. uint8_t length;
  53. int weight;
  54. struct in6_addr addr;
  55. bool enabled;
  56. char name[];
  57. };
  58. struct device_prefix {
  59. struct vlist_node node;
  60. struct list_head head;
  61. struct list_head assignments;
  62. struct interface *iface;
  63. time_t valid_until;
  64. time_t preferred_until;
  65. struct in6_addr excl_addr;
  66. uint8_t excl_length;
  67. struct in6_addr addr;
  68. uint8_t length;
  69. char pclass[];
  70. };
  71. struct device_route {
  72. struct vlist_node node;
  73. struct interface *iface;
  74. bool enabled;
  75. bool keep;
  76. bool failed;
  77. union if_addr nexthop;
  78. int mtu;
  79. unsigned int type;
  80. unsigned int proto;
  81. time_t valid_until;
  82. /* must be last */
  83. enum device_addr_flags flags;
  84. int metric; /* there can be multiple routes to the same target */
  85. unsigned int table;
  86. unsigned int mask;
  87. unsigned int sourcemask;
  88. union if_addr addr;
  89. union if_addr source;
  90. };
  91. struct device_neighbor {
  92. struct vlist_node node;
  93. bool failed;
  94. bool proxy;
  95. bool keep;
  96. bool enabled;
  97. bool router;
  98. uint8_t macaddr[6];
  99. enum device_addr_flags flags;
  100. union if_addr addr;
  101. };
  102. struct device_addr {
  103. struct vlist_node node;
  104. bool enabled;
  105. bool failed;
  106. int index;
  107. unsigned int policy_table;
  108. struct device_route subnet;
  109. /* ipv4 only */
  110. uint32_t broadcast;
  111. uint32_t point_to_point;
  112. /* ipv6 only */
  113. time_t valid_until;
  114. time_t preferred_until;
  115. char *pclass;
  116. /* must be last */
  117. enum device_addr_flags flags;
  118. unsigned int mask;
  119. union if_addr addr;
  120. };
  121. struct device_source_table {
  122. struct list_head head;
  123. uint32_t table;
  124. uint16_t refcount;
  125. uint8_t v6;
  126. uint8_t mask;
  127. union if_addr addr;
  128. };
  129. struct dns_server {
  130. struct vlist_simple_node node;
  131. int af;
  132. union if_addr addr;
  133. };
  134. struct dns_search_domain {
  135. struct vlist_simple_node node;
  136. char name[];
  137. };
  138. extern const struct uci_blob_param_list route_attr_list;
  139. extern const struct uci_blob_param_list neighbor_attr_list;
  140. extern struct list_head prefixes;
  141. void interface_ip_init(struct interface *iface);
  142. void interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list);
  143. void interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list);
  144. void interface_write_resolv_conf(const char *jail);
  145. void interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6);
  146. void interface_ip_add_neighbor(struct interface *iface, struct blob_attr *attr, bool v6);
  147. void interface_ip_update_start(struct interface_ip_settings *ip);
  148. void interface_ip_update_complete(struct interface_ip_settings *ip);
  149. void interface_ip_flush(struct interface_ip_settings *ip);
  150. void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled);
  151. void interface_ip_update_metric(struct interface_ip_settings *ip, int metric);
  152. struct interface *interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface,
  153. bool exclude);
  154. struct device_prefix* interface_ip_add_device_prefix(struct interface *iface,
  155. struct in6_addr *addr, uint8_t length, time_t valid_until, time_t preferred_until,
  156. struct in6_addr *excl_addr, uint8_t excl_length, const char *pclass);
  157. void interface_ip_set_ula_prefix(const char *prefix);
  158. void interface_refresh_assignments(bool hint);
  159. void interface_update_prefix_delegation(struct interface_ip_settings *ip);
  160. #endif