interface.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 *ifname;
  94. const char *jail;
  95. int netns_fd;
  96. bool available;
  97. bool autostart;
  98. bool config_autostart;
  99. bool device_config;
  100. bool enabled;
  101. bool link_state;
  102. bool force_link;
  103. bool dynamic;
  104. bool policy_rules_set;
  105. bool link_up_event;
  106. time_t start_time;
  107. enum interface_state state;
  108. enum interface_config_state config_state;
  109. enum interface_update_flags updated;
  110. struct list_head users;
  111. /* for alias interface */
  112. const char *parent_ifname;
  113. struct interface_user parent_iface;
  114. /* main interface that the interface is bound to */
  115. struct device_user main_dev;
  116. struct device_user ext_dev;
  117. /* interface that layer 3 communication will go through */
  118. struct device_user l3_dev;
  119. struct blob_attr *config;
  120. /* primary protocol state */
  121. const struct proto_handler *proto_handler;
  122. struct interface_proto_state *proto;
  123. struct interface_ip_settings proto_ip;
  124. struct interface_ip_settings config_ip;
  125. struct vlist_tree host_routes;
  126. struct vlist_tree host_neighbors;
  127. int metric;
  128. int dns_metric;
  129. unsigned int ip4table;
  130. unsigned int ip6table;
  131. /* IPv6 assignment parameters */
  132. enum interface_id_selection_type assignment_iface_id_selection;
  133. struct in6_addr assignment_fixed_iface_id;
  134. uint8_t assignment_length;
  135. int32_t assignment_hint;
  136. struct list_head assignment_classes;
  137. int assignment_weight;
  138. /* errors/warnings while trying to bring up the interface */
  139. struct list_head errors;
  140. /* extra data provided by protocol handlers or modules */
  141. struct avl_tree data;
  142. struct uloop_timeout remove_timer;
  143. struct ubus_object ubus;
  144. };
  145. extern struct vlist_tree interfaces;
  146. extern const struct uci_blob_param_list interface_attr_list;
  147. struct interface *interface_alloc(const char *name, struct blob_attr *config, bool dynamic);
  148. bool interface_add(struct interface *iface, struct blob_attr *config);
  149. bool interface_add_alias(struct interface *iface, struct blob_attr *config);
  150. void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
  151. void interface_set_available(struct interface *iface, bool new_state);
  152. void interface_set_up(struct interface *iface);
  153. void interface_set_down(struct interface *iface);
  154. int interface_renew(struct interface *iface);
  155. void interface_set_l3_dev(struct interface *iface, struct device *dev);
  156. void interface_add_user(struct interface_user *dep, struct interface *iface);
  157. void interface_remove_user(struct interface_user *dep);
  158. int interface_handle_link(struct interface *iface, const char *name, bool add, bool link_ext);
  159. void interface_add_error(struct interface *iface, const char *subsystem,
  160. const char *code, const char **data, int n_data);
  161. int interface_add_data(struct interface *iface, const struct blob_attr *data);
  162. int interface_parse_data(struct interface *iface, const struct blob_attr *attr);
  163. void interface_update_start(struct interface *iface, const bool keep_old);
  164. void interface_update_complete(struct interface *iface);
  165. void interface_start_pending(void);
  166. void interface_start_jail(const char *jail, const pid_t netns_pid);
  167. void interface_stop_jail(const char *jail, const pid_t netns_pid);
  168. #endif