IPv6: fix device_prefix vlist_key to not include prefix class
[project/netifd.git] / proto.h
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
17 struct interface;
18 struct interface_proto_state;
19 struct proto_handler;
20
21 enum interface_proto_event {
22         IFPEV_UP,
23         IFPEV_DOWN,
24         IFPEV_LINK_LOST,
25 };
26
27 enum interface_proto_cmd {
28         PROTO_CMD_SETUP,
29         PROTO_CMD_TEARDOWN,
30 };
31
32 enum {
33         PROTO_FLAG_IMMEDIATE = (1 << 0),
34         PROTO_FLAG_NODEV = (1 << 1),
35         PROTO_FLAG_INIT_AVAILABLE = (1 << 2),
36 };
37
38 struct interface_proto_state {
39         const struct proto_handler *handler;
40         struct interface *iface;
41
42         /* filled in by the protocol user */
43         void (*proto_event)(struct interface_proto_state *, enum interface_proto_event ev);
44
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
51
52 struct proto_handler {
53         struct avl_node avl;
54
55         unsigned int flags;
56
57         const char *name;
58         const struct config_param_list *config_params;
59
60         struct interface_proto_state *(*attach)(const struct proto_handler *h,
61                 struct interface *iface, struct blob_attr *attr);
62 };
63
64 extern const struct config_param_list proto_ip_attr;
65
66 void add_proto_handler(struct proto_handler *p);
67 void proto_init_interface(struct interface *iface, struct blob_attr *attr);
68 void proto_attach_interface(struct interface *iface, const char *proto_name);
69 int interface_proto_event(struct interface_proto_state *proto,
70                           enum interface_proto_cmd cmd, bool force);
71
72 unsigned int parse_netmask_string(const char *str, bool v6);
73 int proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr);
74 int proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ext);
75 void proto_dump_handlers(struct blob_buf *b);
76
77 #endif