proto.h 2.3 KB

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