proto.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_PROTO_H
  15. #define __NETIFD_PROTO_H
  16. struct interface;
  17. struct interface_proto_state;
  18. struct proto_handler;
  19. enum interface_proto_event {
  20. IFPEV_UP,
  21. IFPEV_DOWN,
  22. IFPEV_LINK_LOST,
  23. IFPEV_RENEW,
  24. };
  25. enum interface_proto_cmd {
  26. PROTO_CMD_SETUP,
  27. PROTO_CMD_TEARDOWN,
  28. PROTO_CMD_RENEW,
  29. };
  30. enum {
  31. PROTO_FLAG_IMMEDIATE = (1 << 0),
  32. PROTO_FLAG_NODEV = (1 << 1),
  33. PROTO_FLAG_INIT_AVAILABLE = (1 << 2),
  34. PROTO_FLAG_RENEW_AVAILABLE = (1 << 3),
  35. };
  36. struct interface_proto_state {
  37. const struct proto_handler *handler;
  38. struct interface *iface;
  39. /* filled in by the protocol user */
  40. void (*proto_event)(struct interface_proto_state *, enum interface_proto_event ev);
  41. /* filled in by the protocol handler */
  42. int (*notify)(struct interface_proto_state *, struct blob_attr *data);
  43. int (*cb)(struct interface_proto_state *, enum interface_proto_cmd cmd, bool force);
  44. void (*free)(struct interface_proto_state *);
  45. };
  46. struct proto_handler {
  47. struct avl_node avl;
  48. unsigned int flags;
  49. const char *name;
  50. const struct uci_blob_param_list *config_params;
  51. struct interface_proto_state *(*attach)(const struct proto_handler *h,
  52. struct interface *iface, struct blob_attr *attr);
  53. };
  54. extern const struct uci_blob_param_list proto_ip_attr;
  55. void add_proto_handler(struct proto_handler *p);
  56. void proto_init_interface(struct interface *iface, struct blob_attr *attr);
  57. void proto_attach_interface(struct interface *iface, const char *proto_name);
  58. int interface_proto_event(struct interface_proto_state *proto,
  59. enum interface_proto_cmd cmd, bool force);
  60. unsigned int parse_netmask_string(const char *str, bool v6);
  61. int proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr);
  62. int proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ext);
  63. void proto_dump_handlers(struct blob_buf *b);
  64. void proto_shell_init(void);
  65. #endif