]>
Commit | Line | Data |
---|---|---|
1fdc9eae | 1 | /* Declarations and definitions for kernel interaction over netlink |
2 | * Copyright (C) 2016 Cumulus Networks, Inc. | |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1fdc9eae | 19 | */ |
20 | ||
21 | #ifndef _ZEBRA_KERNEL_NETLINK_H | |
22 | #define _ZEBRA_KERNEL_NETLINK_H | |
23 | ||
51e94aa7 EDP |
24 | #ifdef __cplusplus |
25 | extern "C" { | |
26 | #endif | |
27 | ||
1fdc9eae | 28 | #ifdef HAVE_NETLINK |
29 | ||
9ed7517b | 30 | #define NL_RCV_PKT_BUF_SIZE 32768 |
1fdc9eae | 31 | #define NL_PKT_BUF_SIZE 8192 |
32 | ||
312a6bee JU |
33 | /* |
34 | * nl_attr_put - add an attribute to the Netlink message. | |
35 | * | |
36 | * Returns true if the attribute could be added to the message (fits into the | |
37 | * buffer), otherwise false is returned. | |
38 | */ | |
39 | extern bool nl_attr_put(struct nlmsghdr *n, unsigned int maxlen, int type, | |
40 | const void *data, unsigned int alen); | |
41 | extern bool nl_attr_put16(struct nlmsghdr *n, unsigned int maxlen, int type, | |
42 | uint16_t data); | |
43 | extern bool nl_attr_put32(struct nlmsghdr *n, unsigned int maxlen, int type, | |
44 | uint32_t data); | |
45 | ||
46 | /* | |
47 | * nl_attr_nest - start an attribute nest. | |
48 | * | |
49 | * Returns a valid pointer to the beginning of the nest if the attribute | |
50 | * describing the nest could be added to the message (fits into the buffer), | |
51 | * otherwise NULL is returned. | |
52 | */ | |
53 | extern struct rtattr *nl_attr_nest(struct nlmsghdr *n, unsigned int maxlen, | |
54 | int type); | |
55 | ||
56 | /* | |
57 | * nl_attr_nest_end - finalize nesting of attributes. | |
58 | * | |
59 | * Updates the length field of the attribute header to include the appeneded | |
60 | * attributes. Returns a total length of the Netlink message. | |
61 | */ | |
62 | extern int nl_attr_nest_end(struct nlmsghdr *n, struct rtattr *nest); | |
63 | ||
64 | /* | |
65 | * nl_attr_rtnh - append a rtnexthop record to the Netlink message. | |
66 | * | |
67 | * Returns a valid pointer to the rtnexthop struct if it could be added to | |
68 | * the message (fits into the buffer), otherwise NULL is returned. | |
69 | */ | |
70 | extern struct rtnexthop *nl_attr_rtnh(struct nlmsghdr *n, unsigned int maxlen); | |
71 | ||
72 | /* | |
73 | * nl_attr_rtnh_end - finalize adding a rtnexthop record. | |
74 | * | |
75 | * Updates the length field of the rtnexthop to include the appeneded | |
76 | * attributes. | |
77 | */ | |
78 | extern void nl_attr_rtnh_end(struct nlmsghdr *n, struct rtnexthop *rtnh); | |
79 | ||
d62a17ae | 80 | extern void netlink_parse_rtattr(struct rtattr **tb, int max, |
81 | struct rtattr *rta, int len); | |
87da6a60 SW |
82 | extern void netlink_parse_rtattr_nested(struct rtattr **tb, int max, |
83 | struct rtattr *rta); | |
d62a17ae | 84 | extern const char *nl_msg_type_to_str(uint16_t msg_type); |
d7c0a89a QY |
85 | extern const char *nl_rtproto_to_str(uint8_t rtproto); |
86 | extern const char *nl_family_to_str(uint8_t family); | |
87 | extern const char *nl_rttype_to_str(uint8_t rttype); | |
1fdc9eae | 88 | |
acfa8927 SW |
89 | #if defined(HANDLE_NETLINK_FUZZING) |
90 | extern bool netlink_read; | |
81a2f870 | 91 | extern void netlink_read_init(const char *fname); |
acfa8927 | 92 | #endif /* HANDLE_NETLINK_FUZZING */ |
2414abd3 | 93 | extern int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int), |
7cdb1a84 | 94 | const struct nlsock *nl, |
8b962e77 | 95 | const struct zebra_dplane_info *dp_info, |
d62a17ae | 96 | int count, int startup); |
2414abd3 DS |
97 | extern int netlink_talk_filter(struct nlmsghdr *h, ns_id_t ns, int startup); |
98 | extern int netlink_talk(int (*filter)(struct nlmsghdr *, ns_id_t, int startup), | |
d62a17ae | 99 | struct nlmsghdr *n, struct nlsock *nl, |
100 | struct zebra_ns *zns, int startup); | |
fd3f8e52 | 101 | extern int netlink_request(struct nlsock *nl, void *req); |
1fdc9eae | 102 | |
e63c7622 JU |
103 | enum netlink_msg_status { |
104 | FRR_NETLINK_SUCCESS, | |
105 | FRR_NETLINK_ERROR, | |
106 | FRR_NETLINK_QUEUED, | |
107 | }; | |
108 | ||
109 | struct nl_batch; | |
110 | ||
111 | /* | |
112 | * netlink_batch_add_msg - add message to the netlink batch using dplane | |
113 | * context object. | |
114 | * | |
115 | * @ctx: Dataplane context | |
116 | * @msg_encoder: A function that encodes dplane context object into | |
117 | * netlink message. Should take dplane context object, | |
118 | * pointer to a buffer and buffer's length as parameters | |
119 | * and should return -1 on error, 0 on buffer overflow or | |
120 | * size of the encoded message. | |
121 | * @extra_msg: In some cases there are two netlink messages for single | |
122 | * context object that need to be handled differently. This flag | |
123 | * distinguishes those. | |
124 | * | |
125 | * Return: Status of the message. | |
126 | */ | |
127 | extern enum netlink_msg_status netlink_batch_add_msg( | |
128 | struct nl_batch *bth, struct zebra_dplane_ctx *ctx, | |
129 | ssize_t (*msg_encoder)(struct zebra_dplane_ctx *, void *, size_t), | |
130 | bool extra_msg); | |
131 | ||
132 | ||
1fdc9eae | 133 | #endif /* HAVE_NETLINK */ |
134 | ||
51e94aa7 EDP |
135 | #ifdef __cplusplus |
136 | } | |
137 | #endif | |
138 | ||
1fdc9eae | 139 | #endif /* _ZEBRA_KERNEL_NETLINK_H */ |