proto.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. PROTO_FLAG_FORCE_LINK_DEFAULT = (1 << 4),
  36. PROTO_FLAG_LASTERROR = (1 << 5),
  37. PROTO_FLAG_TEARDOWN_ON_L3_LINK_DOWN = (1 << 6),
  38. PROTO_FLAG_NO_TASK = (1 << 7),
  39. };
  40. struct interface_proto_state {
  41. const struct proto_handler *handler;
  42. struct interface *iface;
  43. /* filled in by the protocol user */
  44. void (*proto_event)(struct interface_proto_state *, enum interface_proto_event ev);
  45. /* filled in by the protocol handler */
  46. int (*notify)(struct interface_proto_state *, struct blob_attr *data);
  47. int (*cb)(struct interface_proto_state *, enum interface_proto_cmd cmd, bool force);
  48. void (*free)(struct interface_proto_state *);
  49. };
  50. struct proto_handler {
  51. struct avl_node avl;
  52. unsigned int flags;
  53. const char *name;
  54. const struct uci_blob_param_list *config_params;
  55. struct interface_proto_state *(*attach)(const struct proto_handler *h,
  56. struct interface *iface, struct blob_attr *attr);
  57. };
  58. extern const struct uci_blob_param_list proto_ip_attr;
  59. void add_proto_handler(struct proto_handler *p);
  60. void proto_init_interface(struct interface *iface, struct blob_attr *attr);
  61. void proto_attach_interface(struct interface *iface, const char *proto_name);
  62. int interface_proto_event(struct interface_proto_state *proto,
  63. enum interface_proto_cmd cmd, bool force);
  64. unsigned int parse_netmask_string(const char *str, bool v6);
  65. int proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr);
  66. int proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ext);
  67. void proto_dump_handlers(struct blob_buf *b);
  68. void proto_shell_init(void);
  69. #endif