interface-ip.h 4.7 KB

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