diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-06-12 16:42:54 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-06-12 16:42:54 +0000 |
commit | 66fbd863110e4a15f0f9ed66a4bbdd88f88f3931 (patch) | |
tree | c93620560156dca0ce37f993517a2b9bf7e084cc | |
parent | 34990b33a11d8f98c4a3be48b59530a073e5aa1a (diff) |
Move prefixlen2mask and inet6applymask to util.c so that we can kill the
copies in bgpctl.
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 8 | ||||
-rw-r--r-- | usr.sbin/bgpd/kroute.c | 28 | ||||
-rw-r--r-- | usr.sbin/bgpd/util.c | 28 |
3 files changed, 32 insertions, 32 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 45d70a80dad..a8dbaa4c535 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.240 2009/06/07 00:30:23 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.241 2009/06/12 16:42:53 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -740,10 +740,7 @@ void kr_nexthop_delete(struct bgpd_addr *); void kr_show_route(struct imsg *); void kr_ifinfo(char *); int kr_reload(void); -in_addr_t prefixlen2mask(u_int8_t); struct in6_addr *prefixlen2mask6(u_int8_t prefixlen); -void inet6applymask(struct in6_addr *, const struct in6_addr *, - int); /* control.c */ void control_cleanup(const char *); @@ -785,5 +782,8 @@ const char *log_as(u_int32_t); int aspath_snprint(char *, size_t, void *, u_int16_t); int aspath_asprint(char **, void *, u_int16_t); size_t aspath_strlen(void *, u_int16_t); +in_addr_t prefixlen2mask(u_int8_t); +void inet6applymask(struct in6_addr *, const struct in6_addr *, + int); #endif /* __BGPD_H__ */ diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 41fb84531f3..e6d2043672f 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.167 2009/06/05 22:40:24 chris Exp $ */ +/* $OpenBSD: kroute.c,v 1.168 2009/06/12 16:42:53 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1771,15 +1771,6 @@ mask2prefixlen6(struct sockaddr_in6 *sa_in6) return (l); } -in_addr_t -prefixlen2mask(u_int8_t prefixlen) -{ - if (prefixlen == 0) - return (0); - - return (0xffffffff << (32 - prefixlen)); -} - struct in6_addr * prefixlen2mask6(u_int8_t prefixlen) { @@ -1796,23 +1787,6 @@ prefixlen2mask6(u_int8_t prefixlen) return (&mask); } -void -inet6applymask(struct in6_addr *dest, const struct in6_addr *src, int prefixlen) -{ - 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; - - for (i = 0; i < 16; i++) - dest->s6_addr[i] = src->s6_addr[i] & mask.s6_addr[i]; -} - #define ROUNDUP(a) \ (((a) & ((sizeof(long)) - 1)) ? (1 + ((a) | ((sizeof(long)) - 1))) : (a)) diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c index 76589b60c37..b361b8c3a7c 100644 --- a/usr.sbin/bgpd/util.c +++ b/usr.sbin/bgpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.5 2008/11/06 21:16:27 claudio Exp $ */ +/* $OpenBSD: util.c,v 1.6 2009/06/12 16:42:53 claudio Exp $ */ /* * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> @@ -250,3 +250,29 @@ aspath_extract(const void *seg, int pos) memcpy(&as, ptr, sizeof(u_int32_t)); return (ntohl(as)); } + +in_addr_t +prefixlen2mask(u_int8_t prefixlen) +{ + if (prefixlen == 0) + return (0); + + return (0xffffffff << (32 - prefixlen)); +} + +void +inet6applymask(struct in6_addr *dest, const struct in6_addr *src, int prefixlen) +{ + 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; + + for (i = 0; i < 16; i++) + dest->s6_addr[i] = src->s6_addr[i] & mask.s6_addr[i]; +} |