interface.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef __NETIFD_INTERFACE_H
  2. #define __NETIFD_INTERFACE_H
  3. #include "device.h"
  4. #include "config.h"
  5. struct interface;
  6. struct interface_proto_state;
  7. enum interface_event {
  8. IFEV_DOWN,
  9. IFEV_UP,
  10. };
  11. enum interface_state {
  12. IFS_SETUP,
  13. IFS_UP,
  14. IFS_TEARDOWN,
  15. IFS_DOWN,
  16. };
  17. enum interface_config_state {
  18. IFC_NORMAL,
  19. IFC_RELOAD,
  20. IFC_REMOVE
  21. };
  22. struct interface_error {
  23. struct list_head list;
  24. const char *subsystem;
  25. const char *code;
  26. const char *data[];
  27. };
  28. /*
  29. * interface configuration
  30. */
  31. struct interface {
  32. struct vlist_node node;
  33. struct list_head hotplug_list;
  34. enum interface_event hotplug_ev;
  35. char name[IFNAMSIZ];
  36. const char *ifname;
  37. bool available;
  38. bool autostart;
  39. bool config_autostart;
  40. time_t start_time;
  41. enum interface_state state;
  42. enum interface_config_state config_state;
  43. /* main interface that the interface is bound to */
  44. struct device_user main_dev;
  45. /* interface that layer 3 communication will go through */
  46. struct device_user *l3_dev;
  47. struct blob_attr *config;
  48. /* primary protocol state */
  49. const struct proto_handler *proto_handler;
  50. struct interface_proto_state *proto;
  51. struct vlist_tree proto_addr;
  52. struct vlist_tree proto_route;
  53. /* errors/warnings while trying to bring up the interface */
  54. struct list_head errors;
  55. struct uloop_timeout remove_timer;
  56. struct ubus_object ubus;
  57. };
  58. extern struct vlist_tree interfaces;
  59. extern const struct config_param_list interface_attr_list;
  60. void interface_init(struct interface *iface, const char *name,
  61. struct blob_attr *config);
  62. void interface_add(struct interface *iface, struct blob_attr *config);
  63. void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
  64. void interface_set_available(struct interface *iface, bool new_state);
  65. int interface_set_up(struct interface *iface);
  66. int interface_set_down(struct interface *iface);
  67. int interface_add_link(struct interface *iface, struct device *llif);
  68. void interface_remove_link(struct interface *iface, struct device *llif);
  69. void interface_add_error(struct interface *iface, const char *subsystem,
  70. const char *code, const char **data, int n_data);
  71. void interface_queue_event(struct interface *iface, enum interface_event ev);
  72. void interface_dequeue_event(struct interface *iface);
  73. void interface_start_pending(void);
  74. #endif