interface.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 __NETIFD_INTERFACE_H
  15. #define __NETIFD_INTERFACE_H
  16. #include "device.h"
  17. #include "config.h"
  18. struct interface;
  19. struct interface_proto_state;
  20. enum interface_event {
  21. IFEV_DOWN,
  22. IFEV_UP,
  23. IFEV_UP_FAILED,
  24. IFEV_UPDATE,
  25. IFEV_FREE,
  26. IFEV_RELOAD,
  27. IFEV_LINK_UP,
  28. /* send when a new interface created. This is before proto handlers has been attached. */
  29. IFEV_CREATE,
  30. };
  31. enum interface_state {
  32. IFS_SETUP,
  33. IFS_UP,
  34. IFS_TEARDOWN,
  35. IFS_DOWN,
  36. };
  37. enum interface_config_state {
  38. IFC_NORMAL,
  39. IFC_RELOAD,
  40. IFC_REMOVE
  41. };
  42. enum interface_id_selection_type {
  43. IFID_FIXED,
  44. IFID_RANDOM,
  45. IFID_EUI64
  46. };
  47. enum interface_update_flags {
  48. IUF_ADDRESS = (1 << 0),
  49. IUF_ROUTE = (1 << 1),
  50. IUF_PREFIX = (1 << 2),
  51. IUF_DATA = (1 << 3),
  52. };
  53. struct interface_error {
  54. struct list_head list;
  55. const char *subsystem;
  56. const char *code;
  57. const char *data[];
  58. };
  59. struct interface_user {
  60. struct list_head list;
  61. struct interface *iface;
  62. void (*cb)(struct interface_user *dep, struct interface *iface, enum interface_event ev);
  63. };
  64. struct interface_ip_settings {
  65. struct interface *iface;
  66. bool enabled;
  67. bool no_defaultroute;
  68. bool no_dns;
  69. bool no_delegation;
  70. struct vlist_tree addr;
  71. struct vlist_tree route;
  72. struct vlist_tree prefix;
  73. struct vlist_tree neighbor;
  74. struct vlist_simple_tree dns_servers;
  75. struct vlist_simple_tree dns_search;
  76. };
  77. struct interface_data {
  78. struct avl_node node;
  79. struct blob_attr data[];
  80. };
  81. struct interface_assignment_class {
  82. struct list_head head;
  83. char name[];
  84. };
  85. /*
  86. * interface configuration
  87. */
  88. struct interface {
  89. struct vlist_node node;
  90. struct list_head hotplug_list;
  91. enum interface_event hotplug_ev;
  92. const char *name;
  93. const char *device;
  94. const char *zone;
  95. char *jail;
  96. char *jail_device;
  97. char *host_device;
  98. int netns_fd;
  99. bool available;
  100. bool autostart;
  101. bool config_autostart;
  102. bool device_config;
  103. bool enabled;
  104. bool link_state;
  105. bool force_link;
  106. bool dynamic;
  107. bool policy_rules_set;
  108. bool link_up_event;
  109. time_t start_time;
  110. enum interface_state state;
  111. enum interface_config_state config_state;
  112. enum interface_update_flags updated;
  113. struct list_head users;
  114. /* for alias interface */
  115. const char *parent_ifname;
  116. struct interface_user parent_iface;
  117. /* main interface that the interface is bound to */
  118. struct device_user main_dev;
  119. struct device_user ext_dev;
  120. /* interface that layer 3 communication will go through */
  121. struct device_user l3_dev;
  122. struct blob_attr *config;
  123. /* primary protocol state */
  124. const struct proto_handler *proto_handler;
  125. struct interface_proto_state *proto;
  126. struct interface_ip_settings proto_ip;
  127. struct interface_ip_settings config_ip;
  128. struct vlist_tree host_routes;
  129. struct vlist_tree host_neighbors;
  130. int metric;
  131. int dns_metric;
  132. unsigned int ip4table;
  133. unsigned int ip6table;
  134. /* IPv6 assignment parameters */
  135. enum interface_id_selection_type assignment_iface_id_selection;
  136. struct in6_addr assignment_fixed_iface_id;
  137. uint8_t assignment_length;
  138. int32_t assignment_hint;
  139. struct list_head assignment_classes;
  140. int assignment_weight;
  141. /* errors/warnings while trying to bring up the interface */
  142. struct list_head errors;
  143. /* extra data provided by protocol handlers or modules */
  144. struct avl_tree data;
  145. struct uloop_timeout remove_timer;
  146. struct ubus_object ubus;
  147. };
  148. extern struct vlist_tree interfaces;
  149. extern const struct uci_blob_param_list interface_attr_list;
  150. struct interface *interface_alloc(const char *name, struct blob_attr *config, bool dynamic);
  151. bool interface_add(struct interface *iface, struct blob_attr *config);
  152. bool interface_add_alias(struct interface *iface, struct blob_attr *config);
  153. void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
  154. void interface_set_available(struct interface *iface, bool new_state);
  155. void interface_set_up(struct interface *iface);
  156. void interface_set_down(struct interface *iface);
  157. int interface_renew(struct interface *iface);
  158. void interface_set_l3_dev(struct interface *iface, struct device *dev);
  159. void interface_add_user(struct interface_user *dep, struct interface *iface);
  160. void interface_remove_user(struct interface_user *dep);
  161. int interface_handle_link(struct interface *iface, const char *name, struct blob_attr *vlan, bool add, bool link_ext);
  162. void interface_add_error(struct interface *iface, const char *subsystem,
  163. const char *code, const char **data, int n_data);
  164. int interface_add_data(struct interface *iface, const struct blob_attr *data);
  165. int interface_parse_data(struct interface *iface, const struct blob_attr *attr);
  166. void interface_update_start(struct interface *iface, const bool keep_old);
  167. void interface_update_complete(struct interface *iface);
  168. void interface_start_pending(void);
  169. void interface_start_jail(int netns_fd, const char *jail);
  170. void interface_stop_jail(int netns_fd);
  171. #endif