diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-03-23 20:15:51 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-03-23 20:15:51 +0000 |
commit | 4170cecbef3bba8a62d7099a80d5c8270c3aece6 (patch) | |
tree | 3e8d0c0e38ef7d98eee50cb3f092e41d72885702 /usr.sbin | |
parent | 4c556a8bcd48d9a15100dce7fd7d4f3505d0f23a (diff) |
prefixlen2mask() should return a network byte order result as it does imply
by using an in_addr_t as return type. It simplyfies also the usage as in most
cases the mask is used with a struct in_addr address which is also network
byte order. Add prototypes of prefixlen2mask() and mask2prefixlen() to
ospfd.h as it is used or will be used at different places.
OK norby@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ospfd/kroute.c | 14 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 5 | ||||
-rw-r--r-- | usr.sbin/ospfd/rde_spf.c | 3 |
3 files changed, 9 insertions, 13 deletions
diff --git a/usr.sbin/ospfd/kroute.c b/usr.sbin/ospfd/kroute.c index b5aa2939458..5988111e3d5 100644 --- a/usr.sbin/ospfd/kroute.c +++ b/usr.sbin/ospfd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.8 2005/03/23 11:30:21 henning Exp $ */ +/* $OpenBSD: kroute.c,v 1.9 2005/03/23 20:15:50 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -88,8 +88,6 @@ struct kroute_node *kroute_match(in_addr_t); int protect_lo(void); u_int8_t prefixlen_classful(in_addr_t); -u_int8_t mask2prefixlen(in_addr_t); -in_addr_t prefixlen2mask(u_int8_t); void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); void if_change(u_short, int, struct if_data *); void if_announce(void *); @@ -542,14 +540,10 @@ kroute_match(in_addr_t key) { int i; struct kroute_node *kr; - in_addr_t ina; - - ina = ntohl(key); /* we will never match the default route */ for (i = 32; i > 0; i--) - if ((kr = - kroute_find(htonl(ina & prefixlen2mask(i)), i)) != NULL) + if ((kr = kroute_find(key & prefixlen2mask(i), i)) != NULL) return (kr); /* if we don't have a match yet, try to find a default route */ @@ -612,7 +606,7 @@ prefixlen2mask(u_int8_t prefixlen) if (prefixlen == 0) return (0); - return (0xffffffff << (32 - prefixlen)); + return (htonl(0xffffffff << (32 - prefixlen))); } #define ROUNDUP(a, size) \ @@ -730,7 +724,7 @@ send_rtmsg(int fd, int action, struct kroute *kroute) r.mask.sin_len = sizeof(r.mask); r.mask.sin_family = AF_INET; - r.mask.sin_addr.s_addr = htonl(prefixlen2mask(kroute->prefixlen)); + r.mask.sin_addr.s_addr = prefixlen2mask(kroute->prefixlen); retry: if (write(fd, &r, sizeof(r)) == -1) { diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index 0b89b43e0d3..bd402a60449 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.19 2005/03/23 11:30:21 henning Exp $ */ +/* $OpenBSD: ospfd.h,v 1.20 2005/03/23 20:15:50 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -485,4 +485,7 @@ void kr_show_route(struct imsg *); void kr_ifinfo(char *); struct kif *kif_findname(char *); +u_int8_t mask2prefixlen(in_addr_t); +in_addr_t prefixlen2mask(u_int8_t); + #endif /* _OSPFD_H_ */ diff --git a/usr.sbin/ospfd/rde_spf.c b/usr.sbin/ospfd/rde_spf.c index ba094dca551..cb5b090ac95 100644 --- a/usr.sbin/ospfd/rde_spf.c +++ b/usr.sbin/ospfd/rde_spf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_spf.c,v 1.8 2005/03/22 22:13:48 norby Exp $ */ +/* $OpenBSD: rde_spf.c,v 1.9 2005/03/23 20:15:50 claudio Exp $ */ /* * Copyright (c) 2005 Esben Norby <norby@openbsd.org> @@ -43,7 +43,6 @@ void rt_update(struct in_addr, u_int8_t, struct in_addr, u_int32_t, struct in_addr, struct in_addr, u_int8_t, u_int8_t); void rt_invalidate(void); int linked(struct vertex *, struct vertex *); -u_int8_t mask2prefixlen(in_addr_t); void spf_dump(struct area *area) |