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-private/route/link/api.h>
21 struct ifla_cacheinfo i6_cacheinfo;
22 uint32_t i6_conf[DEVCONF_MAX];
25 static void *inet6_alloc(
struct rtnl_link *link)
30 static void *inet6_clone(
struct rtnl_link *link,
void *data)
34 if ((i6 = inet6_alloc(link)))
35 memcpy(i6, data,
sizeof(*i6));
40 static void inet6_free(
struct rtnl_link *link,
void *data)
45 static struct nla_policy inet6_policy[IFLA_INET6_MAX+1] = {
47 [IFLA_INET6_CACHEINFO] = { .minlen =
sizeof(
struct ifla_cacheinfo) },
48 [IFLA_INET6_CONF] = { .minlen = 4 },
49 [IFLA_INET6_STATS] = { .minlen = 8 },
50 [IFLA_INET6_ICMP6STATS] = { .minlen = 8 },
53 static const uint8_t map_stat_id_from_IPSTATS_MIB_v1[__IPSTATS_MIB_MAX] = {
91 static const uint8_t map_stat_id_from_IPSTATS_MIB_v2[__IPSTATS_MIB_MAX] = {
131 static int inet6_parse_protinfo(
struct rtnl_link *link,
struct nlattr *attr,
135 struct nlattr *tb[IFLA_INET6_MAX+1];
141 if (tb[IFLA_INET6_CONF] &&
nla_len(tb[IFLA_INET6_CONF]) % 4)
143 if (tb[IFLA_INET6_STATS] &&
nla_len(tb[IFLA_INET6_STATS]) % 8)
145 if (tb[IFLA_INET6_ICMP6STATS] &&
nla_len(tb[IFLA_INET6_ICMP6STATS]) % 8)
148 if (tb[IFLA_INET6_FLAGS])
151 if (tb[IFLA_INET6_CACHEINFO])
152 nla_memcpy(&i6->i6_cacheinfo, tb[IFLA_INET6_CACHEINFO],
153 sizeof(i6->i6_cacheinfo));
155 if (tb[IFLA_INET6_CONF])
157 sizeof(i6->i6_conf));
163 if (tb[IFLA_INET6_STATS]) {
164 unsigned char *cnt =
nla_data(tb[IFLA_INET6_STATS]);
167 int len =
nla_len(tb[IFLA_INET6_STATS]) / 8;
168 const uint8_t *map_stat_id = map_stat_id_from_IPSTATS_MIB_v2;
171 (tb[IFLA_INET6_ICMP6STATS] &&
nla_len(tb[IFLA_INET6_ICMP6STATS]) < 6)) {
177 map_stat_id = map_stat_id_from_IPSTATS_MIB_v1;
180 len = min_t(
int, __IPSTATS_MIB_MAX, len);
181 for (i = 1; i < len; i++) {
182 memcpy(&stat, &cnt[i *
sizeof(stat)],
sizeof(stat));
187 if (tb[IFLA_INET6_ICMP6STATS]) {
188 unsigned char *cnt =
nla_data(tb[IFLA_INET6_ICMP6STATS]);
191 int len = min_t(
int, __ICMP6_MIB_MAX,
nla_len(tb[IFLA_INET6_ICMP6STATS]) / 8);
193 for (i = 1; i < len; i++) {
194 memcpy(&stat, &cnt[i *
sizeof(stat)],
sizeof(stat));
204 #define IF_RA_OTHERCONF 0x80
205 #define IF_RA_MANAGED 0x40
206 #define IF_RA_RCVD 0x20
207 #define IF_RS_SENT 0x10
208 #define IF_READY 0x80000000
210 static const struct trans_tbl inet6_flags[] = {
211 __ADD(IF_RA_OTHERCONF, ra_otherconf)
212 __ADD(IF_RA_MANAGED, ra_managed)
213 __ADD(IF_RA_RCVD, ra_rcvd)
214 __ADD(IF_RS_SENT, rs_sent)
215 __ADD(IF_READY, ready)
218 static
char *inet6_flags2str(
int flags,
char *buf,
size_t len)
220 return __flags2str(flags, buf, len, inet6_flags,
221 ARRAY_SIZE(inet6_flags));
224 static const struct trans_tbl inet6_devconf[] = {
225 __ADD(DEVCONF_FORWARDING, forwarding)
226 __ADD(DEVCONF_HOPLIMIT, hoplimit)
227 __ADD(DEVCONF_MTU6, mtu6)
228 __ADD(DEVCONF_ACCEPT_RA, accept_ra)
229 __ADD(DEVCONF_ACCEPT_REDIRECTS, accept_redirects)
230 __ADD(DEVCONF_AUTOCONF, autoconf)
231 __ADD(DEVCONF_DAD_TRANSMITS, dad_transmits)
232 __ADD(DEVCONF_RTR_SOLICITS, rtr_solicits)
233 __ADD(DEVCONF_RTR_SOLICIT_INTERVAL, rtr_solicit_interval)
234 __ADD(DEVCONF_RTR_SOLICIT_DELAY, rtr_solicit_delay)
235 __ADD(DEVCONF_USE_TEMPADDR, use_tempaddr)
236 __ADD(DEVCONF_TEMP_VALID_LFT, temp_valid_lft)
237 __ADD(DEVCONF_TEMP_PREFERED_LFT, temp_prefered_lft)
238 __ADD(DEVCONF_REGEN_MAX_RETRY, regen_max_retry)
239 __ADD(DEVCONF_MAX_DESYNC_FACTOR, max_desync_factor)
240 __ADD(DEVCONF_MAX_ADDRESSES, max_addresses)
241 __ADD(DEVCONF_FORCE_MLD_VERSION, force_mld_version)
242 __ADD(DEVCONF_ACCEPT_RA_DEFRTR, accept_ra_defrtr)
243 __ADD(DEVCONF_ACCEPT_RA_PINFO, accept_ra_pinfo)
244 __ADD(DEVCONF_ACCEPT_RA_RTR_PREF, accept_ra_rtr_pref)
245 __ADD(DEVCONF_RTR_PROBE_INTERVAL, rtr_probe_interval)
246 __ADD(DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN, accept_ra_rt_info)
247 __ADD(DEVCONF_PROXY_NDP, proxy_ndp)
248 __ADD(DEVCONF_OPTIMISTIC_DAD, optimistic_dad)
249 __ADD(DEVCONF_ACCEPT_SOURCE_ROUTE, accept_source_route)
250 __ADD(DEVCONF_MC_FORWARDING, mc_forwarding)
251 __ADD(DEVCONF_DISABLE_IPV6, disable_ipv6)
252 __ADD(DEVCONF_ACCEPT_DAD, accept_dad)
253 __ADD(DEVCONF_FORCE_TLLAO, force_tllao)
256 static
char *inet6_devconf2str(
int type,
char *buf,
size_t len)
258 return __type2str(type, buf, len, inet6_devconf,
259 ARRAY_SIZE(inet6_devconf));
263 static void inet6_dump_details(
struct rtnl_link *link,
267 char buf[64], buf2[64];
270 nl_dump_line(p,
" ipv6 max-reasm-len %s",
271 nl_size2str(i6->i6_cacheinfo.max_reasm_len, buf,
sizeof(buf)));
274 inet6_flags2str(i6->i6_flags, buf,
sizeof(buf)));
277 nl_dump_line(p,
" create-stamp %.2fs reachable-time %s",
278 (
double) i6->i6_cacheinfo.tstamp / 100.,
279 nl_msec2str(i6->i6_cacheinfo.reachable_time, buf,
sizeof(buf)));
281 nl_dump(p,
" retrans-time %s\n",
282 nl_msec2str(i6->i6_cacheinfo.retrans_time, buf,
sizeof(buf)));
284 nl_dump_line(p,
" devconf:\n");
285 nl_dump_line(p,
" ");
287 for (i = 0; i < DEVCONF_MAX; i++) {
288 uint32_t value = i6->i6_conf[i];
292 case DEVCONF_TEMP_VALID_LFT:
293 case DEVCONF_TEMP_PREFERED_LFT:
294 nl_msec2str((uint64_t) value * 1000., buf2,
sizeof(buf2));
297 case DEVCONF_RTR_PROBE_INTERVAL:
298 case DEVCONF_RTR_SOLICIT_INTERVAL:
299 case DEVCONF_RTR_SOLICIT_DELAY:
304 snprintf(buf2,
sizeof(buf2),
"%u", value);
309 inet6_devconf2str(i, buf,
sizeof(buf));
311 offset = 23 - strlen(buf2);
315 for (x = strlen(buf); x < offset; x++)
318 strncpy(&buf[offset], buf2, strlen(buf2));
320 nl_dump_line(p,
"%s", buf);
324 nl_dump_line(p,
" ");
334 static void inet6_dump_stats(
struct rtnl_link *link,
340 nl_dump(p,
" IPv6: InPkts InOctets "
341 " InDiscards InDelivers\n");
347 nl_dump(p,
"%14.2f %3s ", octets, octetsUnit);
349 nl_dump(p,
"%16" PRIu64
" B ", 0);
351 nl_dump(p,
"%18" PRIu64
" %18" PRIu64
"\n",
355 nl_dump(p,
" OutPkts OutOctets "
356 " OutDiscards OutForwards\n");
363 nl_dump(p,
"%14.2f %3s ", octets, octetsUnit);
365 nl_dump(p,
"%16" PRIu64
" B ", 0);
367 nl_dump(p,
"%18" PRIu64
" %18" PRIu64
"\n",
371 nl_dump(p,
" InMcastPkts InMcastOctets "
372 " InBcastPkts InBcastOctests\n");
379 nl_dump(p,
"%14.2f %3s ", octets, octetsUnit);
381 nl_dump(p,
"%16" PRIu64
" B ", 0);
387 nl_dump(p,
"%14.2f %3s\n", octets, octetsUnit);
389 nl_dump(p,
"%16" PRIu64
" B\n", 0);
391 nl_dump(p,
" OutMcastPkts OutMcastOctets "
392 " OutBcastPkts OutBcastOctests\n");
399 nl_dump(p,
"%14.2f %3s ", octets, octetsUnit);
401 nl_dump(p,
"%16" PRIu64
" B ", 0);
407 nl_dump(p,
"%14.2f %3s\n", octets, octetsUnit);
409 nl_dump(p,
"%16" PRIu64
" B\n", 0);
411 nl_dump(p,
" ReasmOKs ReasmFails "
412 " ReasmReqds ReasmTimeout\n");
413 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
419 nl_dump(p,
" FragOKs FragFails "
421 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
426 nl_dump(p,
" InHdrErrors InTooBigErrors "
427 " InNoRoutes InAddrErrors\n");
428 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
434 nl_dump(p,
" InUnknownProtos InTruncatedPkts "
435 " OutNoRoutes InCsumErrors\n");
436 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
442 nl_dump(p,
" InNoECTPkts InECT1Pkts "
443 " InECT0Pkts InCEPkts\n");
444 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
450 nl_dump(p,
" ICMPv6: InMsgs InErrors "
451 " OutMsgs OutErrors InCsumErrors\n");
452 nl_dump(p,
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
" %18" PRIu64
"\n",
460 static const struct nla_policy protinfo_policy = {
464 static struct rtnl_link_af_ops inet6_ops = {
465 .ao_family = AF_INET6,
466 .ao_alloc = &inet6_alloc,
467 .ao_clone = &inet6_clone,
468 .ao_free = &inet6_free,
469 .ao_parse_protinfo = &inet6_parse_protinfo,
470 .ao_parse_af = &inet6_parse_protinfo,
473 .ao_protinfo_policy = &protinfo_policy,
476 static void __init inet6_init(
void)
481 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.
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
Convert milliseconds to a character string.
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.
Dump all attributes but no statistics.
int nla_memcpy(void *dest, struct nlattr *src, int count)
Copy attribute payload to another memory area.
char * nl_size2str(const size_t size, char *buf, const size_t len)
Convert a size toa character string.
double nl_cancel_down_bytes(unsigned long long l, char **unit)
Cancel down a byte counter.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, struct nla_policy *policy)
Create attribute index based on nested attribute.
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 .
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.
uint32_t nla_get_u32(struct nlattr *nla)
Return payload of 32 bit integer attribute.
Dump all attributes including statistics.