diff options
author | Renato Westphal <renato@cvs.openbsd.org> | 2016-01-15 12:25:44 +0000 |
---|---|---|
committer | Renato Westphal <renato@cvs.openbsd.org> | 2016-01-15 12:25:44 +0000 |
commit | 7a678cec5095d3b8197538ccf515b0a0d84115dc (patch) | |
tree | 7ea4b43ff762ec4ab2c6b3f947c59868bd9b7380 /usr.sbin | |
parent | bcb0cbbafdd30991cc518327a72fa03ecd291d26 (diff) |
Avoid the use of inet_pton() whenever possible.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/eigrpd/eigrp.h | 11 | ||||
-rw-r--r-- | usr.sbin/eigrpd/interface.c | 8 | ||||
-rw-r--r-- | usr.sbin/eigrpd/packet.c | 9 | ||||
-rw-r--r-- | usr.sbin/eigrpd/rde.c | 12 |
4 files changed, 22 insertions, 18 deletions
diff --git a/usr.sbin/eigrpd/eigrp.h b/usr.sbin/eigrpd/eigrp.h index 359585b730e..9f81c6f5289 100644 --- a/usr.sbin/eigrpd/eigrp.h +++ b/usr.sbin/eigrpd/eigrp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrp.h,v 1.2 2015/10/04 22:54:38 renato Exp $ */ +/* $OpenBSD: eigrp.h,v 1.3 2016/01/15 12:25:43 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -27,10 +27,15 @@ /* misc */ #define EIGRP_VERSION 2 #define IPPROTO_EIGRP 88 -#define AllEIGRPRouters_v4 0xa0000e0 /* network byte order */ -#define AllEIGRPRouters_v6 "ff02::a" #define EIGRP_IP_TTL 2 +/* 224.0.0.10 */ +#define AllEIGRPRouters_v4 0xa0000e0 /* network byte order */ +/* ff02::a */ +#define AllEIGRPRouters_v6 \ + {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a }}} + #define EIGRP_INFINITE_METRIC ((uint32_t )(~0)) #define RTP_RTRNS_INTERVAL 5 diff --git a/usr.sbin/eigrpd/interface.c b/usr.sbin/eigrpd/interface.c index 26df5bdb5a6..09c323bfc41 100644 --- a/usr.sbin/eigrpd/interface.c +++ b/usr.sbin/eigrpd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.9 2015/10/25 00:43:35 renato Exp $ */ +/* $OpenBSD: interface.c,v 1.10 2016/01/15 12:25:43 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -349,7 +349,7 @@ eigrp_if_start(struct eigrp_iface *ei) struct if_addr *if_addr; union eigrpd_addr addr; struct in_addr addr4; - struct in6_addr addr6; + struct in6_addr addr6 = AllEIGRPRouters_v6; log_debug("%s: %s as %u family %s", __func__, ei->iface->name, eigrp->as, af_name(eigrp->af)); @@ -379,7 +379,6 @@ eigrp_if_start(struct eigrp_iface *ei) return; break; case AF_INET6: - inet_pton(AF_INET6, AllEIGRPRouters_v6, &addr6); if (if_join_ipv6_group(ei->iface, &addr6)) return; break; @@ -395,7 +394,7 @@ eigrp_if_reset(struct eigrp_iface *ei) { struct eigrp *eigrp = ei->eigrp; struct in_addr addr4; - struct in6_addr addr6; + struct in6_addr addr6 = AllEIGRPRouters_v6; struct nbr *nbr; log_debug("%s: %s as %u family %s", __func__, ei->iface->name, @@ -413,7 +412,6 @@ eigrp_if_reset(struct eigrp_iface *ei) if_leave_ipv4_group(ei->iface, &addr4); break; case AF_INET6: - inet_pton(AF_INET6, AllEIGRPRouters_v6, &addr6); if_leave_ipv6_group(ei->iface, &addr6); break; default: diff --git a/usr.sbin/eigrpd/packet.c b/usr.sbin/eigrpd/packet.c index 9dfa9e08ed8..6577ab075ca 100644 --- a/usr.sbin/eigrpd/packet.c +++ b/usr.sbin/eigrpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.5 2015/12/13 18:55:53 renato Exp $ */ +/* $OpenBSD: packet.c,v 1.6 2016/01/15 12:25:43 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -118,6 +118,7 @@ static int send_packet_v6(struct iface *iface, struct nbr *nbr, struct ibuf *buf) { struct sockaddr_in6 sa6; + struct in6_addr maddr = AllEIGRPRouters_v6; /* setup sockaddr */ memset(&sa6, 0, sizeof(sa6)); @@ -126,7 +127,7 @@ send_packet_v6(struct iface *iface, struct nbr *nbr, struct ibuf *buf) if (nbr) sa6.sin6_addr = nbr->addr.v6; else - inet_pton(AF_INET6, AllEIGRPRouters_v6, &sa6.sin6_addr); + memcpy(&sa6.sin6_addr, &maddr, sizeof(sa6.sin6_addr)); addscope(&sa6, iface->ifindex); /* set outgoing interface for multicast traffic */ @@ -576,7 +577,6 @@ recv_packet_v6(int fd, short event, void *bula) } cmsgbuf; struct msghdr msg; struct iovec iov; - struct in6_addr maddr; struct sockaddr_in6 sin6; struct eigrp_hdr *eigrp_hdr; struct iface *iface; @@ -586,6 +586,7 @@ recv_packet_v6(int fd, short event, void *bula) uint16_t len; unsigned int ifindex = 0; union eigrpd_addr src, dest; + struct in6_addr maddr = AllEIGRPRouters_v6; if (event != EV_READ) return; @@ -628,8 +629,6 @@ recv_packet_v6(int fd, short event, void *bula) * Packet needs to be sent to AllEIGRPRouters_v6 or to the * link local address of the interface. */ - inet_pton(AF_INET6, AllEIGRPRouters_v6, &maddr); - if (!IN6_ARE_ADDR_EQUAL(&dest.v6, &maddr) && !IN6_ARE_ADDR_EQUAL(&dest.v6, &iface->linklocal)) { log_debug("%s: packet sent to wrong address %s, interface %s", diff --git a/usr.sbin/eigrpd/rde.c b/usr.sbin/eigrpd/rde.c index ec733b39d61..6e2152aa56e 100644 --- a/usr.sbin/eigrpd/rde.c +++ b/usr.sbin/eigrpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.8 2015/12/05 15:49:01 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.9 2016/01/15 12:25:43 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -489,6 +489,7 @@ rde_send_change_kroute(struct rt_node *rn, struct eigrp_route *route) { struct eigrp *eigrp = route->nbr->eigrp; struct kroute kr; + struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT; log_debug("%s: %s nbr %s", __func__, log_prefix(rn), log_addr(eigrp->af, &route->nbr->addr)); @@ -506,10 +507,10 @@ rde_send_change_kroute(struct rt_node *rn, struct eigrp_route *route) else { switch (eigrp->af) { case AF_INET: - inet_pton(AF_INET, "127.0.0.1", &kr.nexthop.v4); + kr.nexthop.v4.s_addr = htonl(INADDR_LOOPBACK); break; case AF_INET6: - inet_pton(AF_INET, "::1", &kr.nexthop.v6); + memcpy(&kr.nexthop.v6, &lo6, sizeof(kr.nexthop.v6)); break; default: fatalx("rde_send_delete_kroute: unknown af"); @@ -536,6 +537,7 @@ rde_send_delete_kroute(struct rt_node *rn, struct eigrp_route *route) { struct eigrp *eigrp = route->nbr->eigrp; struct kroute kr; + struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT; log_debug("%s: %s nbr %s", __func__, log_prefix(rn), log_addr(eigrp->af, &route->nbr->addr)); @@ -553,10 +555,10 @@ rde_send_delete_kroute(struct rt_node *rn, struct eigrp_route *route) else { switch (eigrp->af) { case AF_INET: - inet_pton(AF_INET, "127.0.0.1", &kr.nexthop.v4); + kr.nexthop.v4.s_addr = htonl(INADDR_LOOPBACK); break; case AF_INET6: - inet_pton(AF_INET, "::1", &kr.nexthop.v6); + memcpy(&kr.nexthop.v6, &lo6, sizeof(kr.nexthop.v6)); break; default: fatalx("rde_send_delete_kroute: unknown af"); |