static int proc_ipv6_route_read () { FILE *fp; char buf [RT_BUFSIZ]; /* Open /proc filesystem */ fp = fopen (_PATH_PROCNET_ROUTE6, "r"); if (fp == NULL) { zlog_warn ("Can't open %s : %s", _PATH_PROCNET_ROUTE6, safe_strerror (errno)); return -1; } /* There is no title line, so we don't drop first line. */ while (fgets (buf, RT_BUFSIZ, fp) != NULL) { int n; char dest[33], src[33], gate[33]; char iface[INTERFACE_NAMSIZ]; int dest_plen, src_plen; int metric, use, refcnt, flags; struct prefix_ipv6 p; struct in6_addr gateway; u_char zebra_flags = 0; /* Linux 2.1.x write this information at net/ipv6/route.c rt6_info_node () */ n = sscanf (buf, "%32s %02x %32s %02x %32s %08x %08x %08x %08x %s", dest, &dest_plen, src, &src_plen, gate, &metric, &use, &refcnt, &flags, iface); if (n != 10) { /* zlog_warn ("can't read all of routing information %d\n%s\n", n, buf); */ continue; } if (! (flags & RTF_UP)) continue; if (! (flags & RTF_GATEWAY)) continue; if (flags & RTF_DYNAMIC) zebra_flags |= ZEBRA_FLAG_SELFROUTE; p.family = AF_INET6; str2in6_addr (dest, &p.prefix); str2in6_addr (gate, &gateway); p.prefixlen = dest_plen; rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, zebra_flags, &p, &gateway, 0, 0, metric, 0); } fclose (fp); return 0; }
int ifaddr_proc_ipv6 () { FILE *fp; char buf[PROCBUFSIZ]; int n; char addr[33]; char ifname[20]; int ifindex, plen, scope, status; struct interface *ifp; struct prefix_ipv6 p; /* Open proc file system. */ fp = fopen (_PATH_PROC_NET_IF_INET6, "r"); if (fp == NULL) { zlog_warn ("Can't open proc file %s: %s", _PATH_PROC_NET_IF_INET6, strerror (errno)); return -1; } /* Get interface's IPv6 address. */ while (fgets (buf, PROCBUFSIZ, fp) != NULL) { n = sscanf (buf, "%32s %02x %02x %02x %02x %20s", addr, &ifindex, &plen, &scope, &status, ifname); if (n != 6) continue; ifp = if_get_by_name (ifname); /* Fetch interface's IPv6 address. */ str2in6_addr (addr, &p.prefix); p.prefixlen = plen; connected_add_ipv6 (ifp, &p.prefix, p.prefixlen, NULL); } return 0; }