diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-06-25 20:08:47 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-06-25 20:08:47 +0000 |
commit | 75aa34b1fe9c93dbec9e03a833bfc9dd1fce8023 (patch) | |
tree | 40d207a04def41d83676464c07688e266802c052 /usr.sbin | |
parent | bea35c4e5848db0f17ca06800d4d14e21edc1e71 (diff) |
provide mask2prefixlen6() and prefixlen2mask6()
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 30 | ||||
-rw-r--r-- | usr.sbin/bgpd/kroute.c | 34 |
2 files changed, 49 insertions, 15 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 82697d6f65f..0823e88199d 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.131 2004/06/23 00:11:27 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.132 2004/06/25 20:08:46 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -594,20 +594,22 @@ void imsg_free(struct imsg *); int imsg_get_fd(struct imsgbuf *); /* kroute.c */ -int kr_init(int); -int kr_change(struct kroute *); -int kr_delete(struct kroute *); -void kr_shutdown(void); -void kr_fib_couple(void); -void kr_fib_decouple(void); -int kr_dispatch_msg(void); -int kr_nexthop_add(struct bgpd_addr *); -void kr_nexthop_delete(struct bgpd_addr *); -void kr_show_route(struct imsg *); -in_addr_t prefixlen2mask(u_int8_t); -int prefix_equal(const struct bgpd_addr *, const struct bgpd_addr *, +int kr_init(int); +int kr_change(struct kroute *); +int kr_delete(struct kroute *); +void kr_shutdown(void); +void kr_fib_couple(void); +void kr_fib_decouple(void); +int kr_dispatch_msg(void); +int kr_nexthop_add(struct bgpd_addr *); +void kr_nexthop_delete(struct bgpd_addr *); +void kr_show_route(struct imsg *); +in_addr_t prefixlen2mask(u_int8_t); +struct in6_addr *prefixlen2mask6(u_int8_t prefixlen); +int prefix_equal(const struct bgpd_addr *, + const struct bgpd_addr *, int); +void inet6applymask(struct in6_addr *, const struct in6_addr *, int); -void inet6applymask(struct in6_addr *, const struct in6_addr *, int); /* control.c */ diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 30d75a9c421..1de69983aae 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.99 2004/06/25 18:48:18 henning Exp $ */ +/* $OpenBSD: kroute.c,v 1.100 2004/06/25 20:08:46 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -104,6 +104,7 @@ void kroute_detach_nexthop(struct knexthop_node *); int protect_lo(void); u_int8_t prefixlen_classful(in_addr_t); u_int8_t mask2prefixlen(in_addr_t); +u_int8_t mask2prefixlen6(struct in6_addr *); void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); void if_change(u_short, int, struct if_data *); void if_announce(void *); @@ -839,12 +840,43 @@ mask2prefixlen(in_addr_t ina) return (33 - ffs(ntohl(ina))); } +u_int8_t +mask2prefixlen6(struct in6_addr *in6a) +{ + u_int8_t l, i; + + l = 0; + for (i = 0; i < 16; i ++) + if (in6a->s6_addr[i] == 0) + return (l); + else + l += 9 - ffs(in6a->s6_addr[i]); + + return (l); +} + in_addr_t prefixlen2mask(u_int8_t prefixlen) { return (0xffffffff << (32 - prefixlen)); } +struct in6_addr * +prefixlen2mask6(u_int8_t prefixlen) +{ + static struct in6_addr mask; + int i; + + bzero(&mask, sizeof(mask)); + for (i = 0; i < prefixlen / 8; i++) + mask.s6_addr[i] = 0xff; + i = prefixlen % 8; + if (i) + mask.s6_addr[prefixlen / 8] = 0xff00 >> i; + + return (&mask); +} + int prefix_equal(const struct bgpd_addr *a, const struct bgpd_addr *b, int prefixlen) |