2 * Copyright (C)2005 USAGI/WIDE Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses>.
18 * based on ip.c, iproute.c
22 * Masahide NAKAMURA @USAGI
28 #include <sys/socket.h>
29 #include <netinet/icmp6.h>
32 #include "ip_common.h"
34 /* prefix flags; see kernel's net/ipv6/addrconf.c and include/net/if_inet6.h */
35 #define IF_PREFIX_ONLINK 0x01
36 #define IF_PREFIX_AUTOCONF 0x02
38 int print_prefix(const struct sockaddr_nl
*who
, struct nlmsghdr
*n
, void *arg
)
40 FILE *fp
= (FILE *)arg
;
41 struct prefixmsg
*prefix
= NLMSG_DATA(n
);
42 int len
= n
->nlmsg_len
;
43 struct rtattr
*tb
[RTA_MAX
+1];
44 int family
= preferred_family
;
46 if (n
->nlmsg_type
!= RTM_NEWPREFIX
) {
47 fprintf(stderr
, "Not a prefix: %08x %08x %08x\n",
48 n
->nlmsg_len
, n
->nlmsg_type
, n
->nlmsg_flags
);
52 len
-= NLMSG_LENGTH(sizeof(*prefix
));
54 fprintf(stderr
, "BUG: wrong nlmsg len %d\n", len
);
58 if (family
== AF_UNSPEC
)
60 if (family
!= AF_INET6
)
63 if (prefix
->prefix_family
!= AF_INET6
) {
64 fprintf(stderr
, "incorrect protocol family: %d\n", prefix
->prefix_family
);
67 if (prefix
->prefix_type
!= ND_OPT_PREFIX_INFORMATION
) {
68 fprintf(stderr
, "wrong ND type %d\n", prefix
->prefix_type
);
72 parse_rtattr(tb
, RTA_MAX
, RTM_RTA(prefix
), len
);
74 if (tb
[PREFIX_ADDRESS
]) {
75 fprintf(fp
, "prefix %s/%u",
76 rt_addr_n2a_rta(family
, tb
[PREFIX_ADDRESS
]),
79 fprintf(fp
, "dev %s ", ll_index_to_name(prefix
->prefix_ifindex
));
81 if (prefix
->prefix_flags
& IF_PREFIX_ONLINK
)
82 fprintf(fp
, "onlink ");
83 if (prefix
->prefix_flags
& IF_PREFIX_AUTOCONF
)
84 fprintf(fp
, "autoconf ");
86 if (tb
[PREFIX_CACHEINFO
]) {
87 const struct prefix_cacheinfo
*pc
88 = RTA_DATA(tb
[PREFIX_CACHEINFO
]);
90 fprintf(fp
, "valid %u ", pc
->valid_time
);
91 fprintf(fp
, "preferred %u ", pc
->preferred_time
);