2
0

interface.h 5.0 KB

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