2
0

interface.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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_FREE,
  24. IFEV_RELOAD,
  25. };
  26. enum interface_state {
  27. IFS_SETUP,
  28. IFS_UP,
  29. IFS_TEARDOWN,
  30. IFS_DOWN,
  31. };
  32. enum interface_config_state {
  33. IFC_NORMAL,
  34. IFC_RELOAD,
  35. IFC_REMOVE
  36. };
  37. struct interface_error {
  38. struct list_head list;
  39. const char *subsystem;
  40. const char *code;
  41. const char *data[];
  42. };
  43. struct interface_user {
  44. struct list_head list;
  45. struct interface *iface;
  46. void (*cb)(struct interface_user *dep, struct interface *iface, enum interface_event ev);
  47. };
  48. struct interface_ip_settings {
  49. struct interface *iface;
  50. bool enabled;
  51. bool no_defaultroute;
  52. bool no_dns;
  53. struct vlist_tree addr;
  54. struct vlist_tree route;
  55. struct vlist_tree prefix;
  56. struct vlist_simple_tree dns_servers;
  57. struct vlist_simple_tree dns_search;
  58. };
  59. struct interface_data {
  60. struct avl_node node;
  61. struct blob_attr data[];
  62. };
  63. struct interface_assignment_class {
  64. struct list_head head;
  65. char name[];
  66. };
  67. /*
  68. * interface configuration
  69. */
  70. struct interface {
  71. struct vlist_node node;
  72. struct list_head hotplug_list;
  73. enum interface_event hotplug_ev;
  74. char name[IFNAMSIZ];
  75. const char *ifname;
  76. bool available;
  77. bool autostart;
  78. bool config_autostart;
  79. bool device_config;
  80. time_t start_time;
  81. enum interface_state state;
  82. enum interface_config_state config_state;
  83. struct list_head users;
  84. const char *parent_ifname;
  85. struct interface_user parent_iface;
  86. /* main interface that the interface is bound to */
  87. struct device_user main_dev;
  88. /* interface that layer 3 communication will go through */
  89. struct device_user l3_dev;
  90. struct blob_attr *config;
  91. /* primary protocol state */
  92. const struct proto_handler *proto_handler;
  93. struct interface_proto_state *proto;
  94. struct interface_ip_settings proto_ip;
  95. struct interface_ip_settings config_ip;
  96. struct vlist_tree host_routes;
  97. int metric;
  98. unsigned int ip4table;
  99. unsigned int ip6table;
  100. /* IPv6 assignment parameters */
  101. uint8_t assignment_length;
  102. int32_t assignment_hint;
  103. struct list_head assignment_classes;
  104. /* errors/warnings while trying to bring up the interface */
  105. struct list_head errors;
  106. /* extra data provided by protocol handlers or modules */
  107. struct avl_tree data;
  108. struct uloop_timeout remove_timer;
  109. struct ubus_object ubus;
  110. };
  111. extern struct vlist_tree interfaces;
  112. extern const struct uci_blob_param_list interface_attr_list;
  113. void interface_init(struct interface *iface, const char *name,
  114. struct blob_attr *config);
  115. void interface_add(struct interface *iface, struct blob_attr *config);
  116. bool interface_add_alias(struct interface *iface, struct blob_attr *config);
  117. void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
  118. void interface_set_available(struct interface *iface, bool new_state);
  119. int interface_set_up(struct interface *iface);
  120. int interface_set_down(struct interface *iface);
  121. void __interface_set_down(struct interface *iface, bool force);
  122. void interface_set_main_dev(struct interface *iface, struct device *dev);
  123. void interface_set_l3_dev(struct interface *iface, struct device *dev);
  124. void interface_add_user(struct interface_user *dep, struct interface *iface);
  125. void interface_remove_user(struct interface_user *dep);
  126. int interface_add_link(struct interface *iface, struct device *dev);
  127. int interface_remove_link(struct interface *iface, struct device *dev);
  128. void interface_add_error(struct interface *iface, const char *subsystem,
  129. const char *code, const char **data, int n_data);
  130. int interface_add_data(struct interface *iface, const struct blob_attr *data);
  131. void interface_update_start(struct interface *iface);
  132. void interface_update_complete(struct interface *iface);
  133. void interface_start_pending(void);
  134. #endif