12 #include <netlink-private/netlink.h> 13 #include <netlink/netlink.h> 14 #include <netlink/attr.h> 15 #include <netlink/route/rtnl.h> 16 #include <netlink/route/link/inet6.h> 17 #include <netlink-private/route/link/api.h> 19 #include "netlink-private/utils.h" 21 #define I6_ADDR_GEN_MODE_UNKNOWN UINT8_MAX 26 struct ifla_cacheinfo i6_cacheinfo;
27 uint32_t i6_conf[DEVCONF_MAX];
28 struct in6_addr i6_token;
29 uint8_t i6_addr_gen_mode;
32 static void *inet6_alloc(
struct rtnl_link *link)
38 i6->i6_addr_gen_mode = I6_ADDR_GEN_MODE_UNKNOWN;
43 static void *inet6_clone(
struct rtnl_link *link,
void *data)
47 if ((i6 = inet6_alloc(link)))
48 memcpy(i6, data,
sizeof(*i6));
53 static void inet6_free(
struct rtnl_link *link,
void *data)
58 static struct nla_policy inet6_policy[IFLA_INET6_MAX+1] = {
60 [IFLA_INET6_CACHEINFO] = { .minlen =
sizeof(
struct ifla_cacheinfo) },
61 [IFLA_INET6_CONF] = { .minlen = 4 },
62 [IFLA_INET6_STATS] = { .minlen = 8 },
63 [IFLA_INET6_ICMP6STATS] = { .minlen = 8 },
64 [IFLA_INET6_TOKEN] = { .minlen =
sizeof(
struct in6_addr) },
65 [IFLA_INET6_ADDR_GEN_MODE] = { .type =
NLA_U8 },
68 static const uint8_t map_stat_id_from_IPSTATS_MIB_v1[__IPSTATS_MIB_MAX] = {
106 static const uint8_t map_stat_id_from_IPSTATS_MIB_v2[__IPSTATS_MIB_MAX] = {
146 static int inet6_parse_protinfo(
struct rtnl_link *link,
struct nlattr *attr,
150 struct nlattr *tb[IFLA_INET6_MAX+1];
156 if (tb[IFLA_INET6_CONF] &&
nla_len(tb[IFLA_INET6_CONF]) % 4)
158 if (tb[IFLA_INET6_STATS] &&
nla_len(tb[IFLA_INET6_STATS]) % 8)
160 if (tb[IFLA_INET6_ICMP6STATS] &&
nla_len(tb[IFLA_INET6_ICMP6STATS]) % 8)
163 if (tb[IFLA_INET6_FLAGS])
166 if (tb[IFLA_INET6_CACHEINFO])
167 nla_memcpy(&i6->i6_cacheinfo, tb[IFLA_INET6_CACHEINFO],
168 sizeof(i6->i6_cacheinfo));
170 if (tb[IFLA_INET6_CONF])
172 sizeof(i6->i6_conf));
174 if (tb[IFLA_INET6_TOKEN])
175 nla_memcpy(&i6->i6_token, tb[IFLA_INET6_TOKEN],
176 sizeof(
struct in6_addr));
178 if (tb[IFLA_INET6_ADDR_GEN_MODE])
179 i6->i6_addr_gen_mode =
nla_get_u8 (tb[IFLA_INET6_ADDR_GEN_MODE]);
185 if (tb[IFLA_INET6_STATS]) {
186 unsigned char *cnt =
nla_data(tb[IFLA_INET6_STATS]);
189 int len =
nla_len(tb[IFLA_INET6_STATS]) / 8;
190 const uint8_t *map_stat_id = map_stat_id_from_IPSTATS_MIB_v2;
193 (tb[IFLA_INET6_ICMP6STATS] &&
nla_len(tb[IFLA_INET6_ICMP6STATS]) < 6)) {
199 map_stat_id = map_stat_id_from_IPSTATS_MIB_v1;
202 len = min_t(
int, __IPSTATS_MIB_MAX, len);
203 for (i = 1; i < len; i++) {
204 memcpy(&stat, &cnt[i *
sizeof(stat)],
sizeof(stat));
209 if (tb[IFLA_INET6_ICMP6STATS]) {
210 unsigned char *cnt =
nla_data(tb[IFLA_INET6_ICMP6STATS]);
213 int len = min_t(
int, __ICMP6_MIB_MAX,
nla_len(tb[IFLA_INET6_ICMP6STATS]) / 8);
215 for (i = 1; i < len; i++) {
216 memcpy(&stat, &cnt[i *
sizeof(stat)],
sizeof(stat));
225 static int inet6_fill_af(
struct rtnl_link *link,
struct nl_msg *msg,
void *data)
229 if (id->i6_addr_gen_mode != I6_ADDR_GEN_MODE_UNKNOWN)
230 NLA_PUT_U8(msg, IFLA_INET6_ADDR_GEN_MODE, id->i6_addr_gen_mode);
239 #define IF_RA_OTHERCONF 0x80 240 #define IF_RA_MANAGED 0x40 241 #define IF_RA_RCVD 0x20 242 #define IF_RS_SENT 0x10 243 #define IF_READY 0x80000000 245 static const struct trans_tbl inet6_flags[] = {
246 __ADD(IF_RA_OTHERCONF, ra_otherconf),
247 __ADD(IF_RA_MANAGED, ra_managed),
248 __ADD(IF_RA_RCVD, ra_rcvd),
249 __ADD(IF_RS_SENT, rs_sent),
250 __ADD(IF_READY, ready),
253 char *rtnl_link_inet6_flags2str(
int flags,
char *buf,
size_t len)
255 return __flags2str(flags, buf, len, inet6_flags,
256 ARRAY_SIZE(inet6_flags));
259 int rtnl_link_inet6_str2flags(
const char *name)
261 return __str2flags(name, inet6_flags, ARRAY_SIZE(inet6_flags));
264 static const struct trans_tbl inet6_devconf[] = {
265 __ADD(DEVCONF_FORWARDING, forwarding),
266 __ADD(DEVCONF_HOPLIMIT, hoplimit),
267 __ADD(DEVCONF_MTU6, mtu6),
268 __ADD(DEVCONF_ACCEPT_RA, accept_ra),
269 __ADD(DEVCONF_ACCEPT_REDIRECTS, accept_redirects),
270 __ADD(DEVCONF_AUTOCONF, autoconf),
271 __ADD(DEVCONF_DAD_TRANSMITS, dad_transmits),
272 __ADD(DEVCONF_RTR_SOLICITS, rtr_solicits),
273 __ADD(DEVCONF_RTR_SOLICIT_INTERVAL, rtr_solicit_interval),
274 __ADD(DEVCONF_RTR_SOLICIT_DELAY, rtr_solicit_delay),
275 __ADD(DEVCONF_USE_TEMPADDR, use_tempaddr),
276 __ADD(DEVCONF_TEMP_VALID_LFT, temp_valid_lft),
277 __ADD(DEVCONF_TEMP_PREFERED_LFT, temp_prefered_lft),
278 __ADD(DEVCONF_REGEN_MAX_RETRY, regen_max_retry),
279 __ADD(DEVCONF_MAX_DESYNC_FACTOR, max_desync_factor),
280 __ADD(DEVCONF_MAX_ADDRESSES, max_addresses),
281 __ADD(DEVCONF_FORCE_MLD_VERSION, force_mld_version),
282 __ADD(DEVCONF_ACCEPT_RA_DEFRTR, accept_ra_defrtr),
283 __ADD(DEVCONF_ACCEPT_RA_PINFO, accept_ra_pinfo),
284 __ADD(DEVCONF_ACCEPT_RA_RTR_PREF, accept_ra_rtr_pref),
285 __ADD(DEVCONF_RTR_PROBE_INTERVAL, rtr_probe_interval),
286 __ADD(DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN, accept_ra_rt_info),
287 __ADD(DEVCONF_PROXY_NDP, proxy_ndp),
288 __ADD(DEVCONF_OPTIMISTIC_DAD, optimistic_dad),
289 __ADD(DEVCONF_ACCEPT_SOURCE_ROUTE, accept_source_route),
290 __ADD(DEVCONF_MC_FORWARDING, mc_forwarding),
291 __ADD(DEVCONF_DISABLE_IPV6, disable_ipv6),
292 __ADD(DEVCONF_ACCEPT_DAD, accept_dad),
293 __ADD(DEVCONF_FORCE_TLLAO, force_tllao),
296 static char *inet6_devconf2str(
int type,
char *buf,
size_t len)
298 return __type2str(type, buf, len, inet6_devconf,
299 ARRAY_SIZE(inet6_devconf));
302 static const struct trans_tbl inet6_addr_gen_mode[] = {
303 __ADD(IN6_ADDR_GEN_MODE_EUI64, eui64),
304 __ADD(IN6_ADDR_GEN_MODE_NONE, none),
305 __ADD(IN6_ADDR_GEN_MODE_STABLE_PRIVACY, stable_privacy),
308 const char *rtnl_link_inet6_addrgenmode2str(uint8_t mode,
char *buf,
size_t len)
310 return __type2str(mode, buf, len, inet6_addr_gen_mode,
311 ARRAY_SIZE(inet6_addr_gen_mode));
314 uint8_t rtnl_link_inet6_str2addrgenmode(
const char *mode)
316 return (uint8_t) __str2type(mode, inet6_addr_gen_mode,
317 ARRAY_SIZE(inet6_addr_gen_mode));
320 static void inet6_dump_details(
struct rtnl_link *link,
324 struct nl_addr *addr;
328 nl_dump_line(p,
" ipv6 max-reasm-len %s",
329 nl_size2str(i6->i6_cacheinfo.max_reasm_len, buf,
sizeof(buf)));
332 rtnl_link_inet6_flags2str(i6->i6_flags, buf,
sizeof(buf)));
334 nl_dump_line(p,
" create-stamp %.2fs reachable-time %s",
335 (
double) i6->i6_cacheinfo.tstamp / 100.,
336 nl_msec2str(i6->i6_cacheinfo.reachable_time, buf,
sizeof(buf)));
338 nl_dump(p,
" retrans-time %s\n",
339 nl_msec2str(i6->i6_cacheinfo.retrans_time, buf,
sizeof(buf)));
341 addr =
nl_addr_build(AF_INET6, &i6->i6_token,
sizeof(i6->i6_token));
346 nl_dump(p,
" link-local address mode %s\n",
347 rtnl_link_inet6_addrgenmode2str(i6->i6_addr_gen_mode,
350 nl_dump_line(p,
" devconf:\n");
351 nl_dump_line(p,
" ");
353 for (i = 0; i < DEVCONF_MAX; i++) {
355 uint32_t value = i6->i6_conf[i];
359 case DEVCONF_TEMP_VALID_LFT:
360 case DEVCONF_TEMP_PREFERED_LFT:
361 nl_msec2str((uint64_t) value * 1000., buf2,
sizeof(buf2));
364 case DEVCONF_RTR_PROBE_INTERVAL:
365 case DEVCONF_RTR_SOLICIT_INTERVAL:
366 case DEVCONF_RTR_SOLICIT_DELAY:
371 snprintf(buf2,
sizeof(buf2),
"%u", value);
375 inet6_devconf2str(i, buf,
sizeof(buf));
377 offset = 23 - strlen(buf2);
381 for (x = strlen(buf); x < offset; x++)
384 _nl_strncpy_trunc(&buf[offset], buf2,
sizeof(buf) - offset);
386 nl_dump_line(p,
"%s", buf);
390 nl_dump_line(p,
" ");
400 static void inet6_dump_stats(
struct rtnl_link *link,
406 nl_dump(p,
" IPv6: InPkts InOctets " 407 " InDiscards InDelivers\n");
413 nl_dump(p,
"%14.2f %3s ", octets, octetsUnit);
415 nl_dump(p,
"%16" PRIu64
" B ", 0);
417 nl_dump(p,
"%18" PRIu64
" %18" PRIu64
"\n",
421 nl_dump(p,
" OutPkts OutOctets " 422 " OutDiscards OutForwards\n");
429 nl_dump(p,
"%14.2f %3s ", octets, octetsUnit);
431 nl_dump(p,
"%16" PRIu64
" B ", 0);
433 nl_dump(p,
"%18" PRIu64
" %18" PRIu64
"\n",
437 nl_dump(p,
" InMcastPkts InMcastOctets " 438 " InBcastPkts InBcastOctests\n");
445 nl_dump(p,
"%14.2f %3s ", octets, octetsUnit);
447 nl_dump(p,
"%16" PRIu64
" B ", 0);
453 nl_dump(p,
"%14.2f %3s\n", octets, octetsUnit);
455 nl_dump(p,
"%16" PRIu64
" B\n", 0);
457 nl_dump(p,
" OutMcastPkts OutMcastOctets " 458 " OutBcastPkts OutBcastOctests\n");
465 nl_dump(p,
"%14.2f %3s ", octets, octetsUnit);
467 nl_dump(p,
"%16" PRIu64
" B ", 0);
473 nl_dump(p,
"%14.2f %3s\n", octets, octetsUnit);
475 nl_dump(p,
"%16" PRIu64
" B\n", 0);
477 nl_dump(p,
" ReasmOKs ReasmFails " 478 " ReasmReqds ReasmTimeout\n");
479 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
485 nl_dump(p,
" FragOKs FragFails " 487 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
492 nl_dump(p,
" InHdrErrors InTooBigErrors " 493 " InNoRoutes InAddrErrors\n");
494 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
500 nl_dump(p,
" InUnknownProtos InTruncatedPkts " 501 " OutNoRoutes InCsumErrors\n");
502 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
508 nl_dump(p,
" InNoECTPkts InECT1Pkts " 509 " InECT0Pkts InCEPkts\n");
510 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
516 nl_dump(p,
" ICMPv6: InMsgs InErrors " 517 " OutMsgs OutErrors InCsumErrors\n");
518 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
526 static const struct nla_policy protinfo_policy = {
530 static struct rtnl_link_af_ops inet6_ops = {
531 .ao_family = AF_INET6,
532 .ao_alloc = &inet6_alloc,
533 .ao_clone = &inet6_clone,
534 .ao_free = &inet6_free,
535 .ao_parse_protinfo = &inet6_parse_protinfo,
536 .ao_parse_af = &inet6_parse_protinfo,
537 .ao_fill_af = &inet6_fill_af,
540 .ao_protinfo_policy = &protinfo_policy,
553 int rtnl_link_inet6_get_flags(
struct rtnl_link *link, uint32_t* out_flags)
560 *out_flags =
id->i6_flags;
574 int rtnl_link_inet6_set_flags(
struct rtnl_link *link, uint32_t flags)
581 id->i6_flags = flags;
597 int rtnl_link_inet6_get_token(
struct rtnl_link *link,
struct nl_addr **addr)
604 *addr =
nl_addr_build(AF_INET6, &id->i6_token,
sizeof(id->i6_token));
627 int rtnl_link_inet6_set_token(
struct rtnl_link *link,
struct nl_addr *addr)
639 sizeof(id->i6_token));
656 int rtnl_link_inet6_get_addr_gen_mode(
struct rtnl_link *link, uint8_t *mode)
663 if (id->i6_addr_gen_mode == I6_ADDR_GEN_MODE_UNKNOWN)
666 *mode =
id->i6_addr_gen_mode;
680 int rtnl_link_inet6_set_addr_gen_mode(
struct rtnl_link *link, uint8_t mode)
687 id->i6_addr_gen_mode = mode;
691 static void __init inet6_init(
void)
696 static void __exit inet6_exit(
void)
int rtnl_link_af_register(struct rtnl_link_af_ops *ops)
Register operations for a link address family.
Attribute validation policy.
uint8_t nla_get_u8(const struct nlattr *nla)
Return value of 8 bit integer attribute.
struct nl_addr * nl_addr_build(int family, const void *buf, size_t size)
Allocate abstract address based on a binary address.
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
Convert milliseconds to a character string.
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
int rtnl_link_af_unregister(struct rtnl_link_af_ops *ops)
Unregister operations for a link address family.
int rtnl_link_set_stat(struct rtnl_link *link, rtnl_link_stat_id_t id, const uint64_t value)
Set value of link statistics counter.
#define NLA_PUT_U8(msg, attrtype, value)
Add 8 bit integer attribute to netlink message.
Dump all attributes but no statistics.
int nl_addr_iszero(const struct nl_addr *addr)
Returns true if the address consists of all zeros.
char * nl_size2str(const size_t size, char *buf, const size_t len)
Convert a size toa character string.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
Create attribute index based on nested attribute.
double nl_cancel_down_bytes(unsigned long long l, char **unit)
Cancel down a byte counter.
int nla_memcpy(void *dest, const struct nlattr *src, int count)
Copy attribute payload to another memory area.
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
int nla_len(const struct nlattr *nla)
Return length of the payload .
void * rtnl_link_af_alloc(struct rtnl_link *link, const struct rtnl_link_af_ops *ops)
Allocate and return data buffer for link address family modules.
void * rtnl_link_af_data(const struct rtnl_link *link, const struct rtnl_link_af_ops *ops)
Return data buffer for link address family modules.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
uint16_t type
Type of attribute or NLA_UNSPEC.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
unsigned int nl_addr_get_len(const struct nl_addr *addr)
Get length of binary address of abstract address object.
Dump all attributes including statistics.
void * nl_addr_get_binary_addr(const struct nl_addr *addr)
Get binary address of abstract address object.
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
int nl_addr_get_family(const struct nl_addr *addr)
Return address family.