]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/kernel_netlink.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Declarations and definitions for kernel interaction over netlink
3 * Copyright (C) 2016 Cumulus Networks, Inc.
6 #ifndef _ZEBRA_KERNEL_NETLINK_H
7 #define _ZEBRA_KERNEL_NETLINK_H
16 ((struct rtattr *)(((char *)(h)) + NLMSG_ALIGN(sizeof(struct nhmsg))))
19 #define NL_RCV_PKT_BUF_SIZE (34 * 1024)
20 #define NL_PKT_BUF_SIZE 8192
23 * nl_attr_put - add an attribute to the Netlink message.
25 * Returns true if the attribute could be added to the message (fits into the
26 * buffer), otherwise false is returned.
28 extern bool nl_attr_put(struct nlmsghdr
*n
, unsigned int maxlen
, int type
,
29 const void *data
, unsigned int alen
);
30 extern bool nl_attr_put8(struct nlmsghdr
*n
, unsigned int maxlen
, int type
,
32 extern bool nl_attr_put16(struct nlmsghdr
*n
, unsigned int maxlen
, int type
,
34 extern bool nl_attr_put32(struct nlmsghdr
*n
, unsigned int maxlen
, int type
,
36 extern bool nl_attr_put64(struct nlmsghdr
*n
, unsigned int maxlen
, int type
,
40 * nl_attr_nest - start an attribute nest.
42 * Returns a valid pointer to the beginning of the nest if the attribute
43 * describing the nest could be added to the message (fits into the buffer),
44 * otherwise NULL is returned.
46 extern struct rtattr
*nl_attr_nest(struct nlmsghdr
*n
, unsigned int maxlen
,
50 * nl_attr_nest_end - finalize nesting of attributes.
52 * Updates the length field of the attribute header to include the appeneded
53 * attributes. Returns a total length of the Netlink message.
55 extern int nl_attr_nest_end(struct nlmsghdr
*n
, struct rtattr
*nest
);
58 * nl_attr_rtnh - append a rtnexthop record to the Netlink message.
60 * Returns a valid pointer to the rtnexthop struct if it could be added to
61 * the message (fits into the buffer), otherwise NULL is returned.
63 extern struct rtnexthop
*nl_attr_rtnh(struct nlmsghdr
*n
, unsigned int maxlen
);
66 * nl_attr_rtnh_end - finalize adding a rtnexthop record.
68 * Updates the length field of the rtnexthop to include the appeneded
71 extern void nl_attr_rtnh_end(struct nlmsghdr
*n
, struct rtnexthop
*rtnh
);
73 extern void netlink_parse_rtattr(struct rtattr
**tb
, int max
,
74 struct rtattr
*rta
, int len
);
75 extern void netlink_parse_rtattr_flags(struct rtattr
**tb
, int max
,
76 struct rtattr
*rta
, int len
,
77 unsigned short flags
);
78 extern void netlink_parse_rtattr_nested(struct rtattr
**tb
, int max
,
81 * nl_addraw_l copies raw form the netlink message buffer into netlink
82 * message header pointer. It ensures the aligned data buffer does not
83 * override past max length.
84 * return value is 0 if its successful
86 extern bool nl_addraw_l(struct nlmsghdr
*n
, unsigned int maxlen
,
87 const void *data
, unsigned int len
);
89 * nl_rta_put - add an additional optional attribute(rtattr) to the
90 * Netlink message buffer.
92 * Returns true if the attribute could be added to the message (fits into the
93 * buffer), otherwise false is returned.
95 extern bool nl_rta_put(struct rtattr
*rta
, unsigned int maxlen
, int type
,
96 const void *data
, int alen
);
97 extern bool nl_rta_put16(struct rtattr
*rta
, unsigned int maxlen
, int type
,
99 extern bool nl_rta_put64(struct rtattr
*rta
, unsigned int maxlen
, int type
,
102 * nl_rta_nest - start an additional optional attribute (rtattr) nest.
104 * Returns a valid pointer to the beginning of the nest if the attribute
105 * describing the nest could be added to the message (fits into the buffer),
106 * otherwise NULL is returned.
108 extern struct rtattr
*nl_rta_nest(struct rtattr
*rta
, unsigned int maxlen
,
111 * nl_rta_nest_end - finalize nesting of an aditionl optionl attributes.
113 * Updates the length field of the attribute header to include the appeneded
114 * attributes. Returns a total length of the Netlink message.
116 extern int nl_rta_nest_end(struct rtattr
*rta
, struct rtattr
*nest
);
117 extern const char *nl_msg_type_to_str(uint16_t msg_type
);
118 extern const char *nl_rtproto_to_str(uint8_t rtproto
);
119 extern const char *nl_family_to_str(uint8_t family
);
120 extern const char *nl_rttype_to_str(uint8_t rttype
);
122 extern int netlink_parse_info(int (*filter
)(struct nlmsghdr
*, ns_id_t
, int),
124 const struct zebra_dplane_info
*dp_info
,
125 int count
, bool startup
);
126 extern int netlink_talk_filter(struct nlmsghdr
*h
, ns_id_t ns
, int startup
);
127 extern int netlink_talk(int (*filter
)(struct nlmsghdr
*, ns_id_t
, int startup
),
128 struct nlmsghdr
*n
, struct nlsock
*nl
,
129 struct zebra_ns
*zns
, bool startup
);
130 extern int netlink_request(struct nlsock
*nl
, void *req
);
132 enum netlink_msg_status
{
141 * netlink_batch_add_msg - add message to the netlink batch using dplane
144 * @ctx: Dataplane context
145 * @msg_encoder: A function that encodes dplane context object into
146 * netlink message. Should take dplane context object,
147 * pointer to a buffer and buffer's length as parameters
148 * and should return -1 on error, 0 on buffer overflow or
149 * size of the encoded message.
150 * @ignore_res: Whether the result of this message should be ignored.
151 * This should be used in some 'update' cases where we
152 * need to send two messages for one context object.
154 * Return: Status of the message.
156 extern enum netlink_msg_status
netlink_batch_add_msg(
157 struct nl_batch
*bth
, struct zebra_dplane_ctx
*ctx
,
158 ssize_t (*msg_encoder
)(struct zebra_dplane_ctx
*, void *, size_t),
164 extern int netlink_config_write_helper(struct vty
*vty
);
167 * Configure size of the batch buffer and sending threshold. If 'unset', reset
170 extern void netlink_set_batch_buffer_size(uint32_t size
, uint32_t threshold
,
173 extern struct nlsock
*kernel_netlink_nlsock_lookup(int sock
);
174 #endif /* HAVE_NETLINK */
180 #endif /* _ZEBRA_KERNEL_NETLINK_H */