summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2013-03-24 12:53:21 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2013-03-24 12:53:21 +0000
commit337a88142ddc7e28df4e31b9b680db8a21bbb6b3 (patch)
treed6476df74562c38ec3f54d40e4d03e2722abe0bc
parent8651fbb679a805cfb74aeefe78f046fc606eae91 (diff)
Simplify logic when processing route dump by using a helper function
delete_route(). No functional change.
-rw-r--r--sbin/dhclient/kroute.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index 17e8a9f85b2..56b1c9ec025 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.45 2013/03/21 04:43:17 deraadt Exp $ */
+/* $OpenBSD: kroute.c,v 1.46 2013/03/24 12:53:20 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -33,6 +33,7 @@ struct in_addr active_addr;
int create_route_label(struct sockaddr_rtlabel *);
int check_route_label(struct sockaddr_rtlabel *);
void populate_rti_info(struct sockaddr **, struct rt_msghdr *);
+void delete_route(int, int, struct rt_msghdr *);
#define ROUTE_LABEL_NONE 1
#define ROUTE_LABEL_NOT_DHCLIENT 2
@@ -85,7 +86,7 @@ priv_flush_routes_and_arp_cache(struct imsg_flush_routes *imsg)
struct sockaddr_dl *sdl;
struct sockaddr_in *sa_in;
struct sockaddr_rtlabel *sa_rl;
- int s, seqno = 0, rlen;
+ int s;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
@@ -145,10 +146,11 @@ priv_flush_routes_and_arp_cache(struct imsg_flush_routes *imsg)
switch (check_route_label(sa_rl)) {
case ROUTE_LABEL_DHCLIENT_OURS:
/* Always delete routes we labeled. */
- goto delete;
+ delete_route(s, imsg->rdomain, rtm);
+ continue;
case ROUTE_LABEL_DHCLIENT_DEAD:
if (imsg->zapzombies)
- goto delete;
+ delete_route(s, imsg->rdomain, rtm);
continue;
case ROUTE_LABEL_DHCLIENT_LIVE:
case ROUTE_LABEL_DHCLIENT_UNKNOWN:
@@ -178,8 +180,8 @@ priv_flush_routes_and_arp_cache(struct imsg_flush_routes *imsg)
case IFT_ISO88024:
case IFT_ISO88025:
case IFT_CARP:
- /* Delete it. */
- goto delete;
+ delete_route(s, imsg->rdomain, rtm);
+ break;
default:
break;
}
@@ -195,25 +197,11 @@ priv_flush_routes_and_arp_cache(struct imsg_flush_routes *imsg)
if (sa_in &&
sa_in->sin_addr.s_addr == INADDR_ANY &&
rtm->rtm_tableid == imsg->rdomain &&
- strcmp(imsg->ifname, ifname) == 0)
- goto delete;
+ strcmp(imsg->ifname, ifname) == 0) {
+ delete_route(s, imsg->rdomain, rtm);
+ continue;
+ }
}
-
- continue;
-
-delete:
- rtm->rtm_type = RTM_DELETE;
- rtm->rtm_seq = seqno;
- rtm->rtm_tableid = imsg->rdomain;
-
- rlen = write(s, next, rtm->rtm_msglen);
- if (rlen == -1) {
- if (errno != ESRCH)
- error("RTM_DELETE write: %s", strerror(errno));
- } else if (rlen < (int)rtm->rtm_msglen)
- error("short RTM_DELETE write (%d)\n", rlen);
-
- seqno++;
}
close(s);
@@ -818,3 +806,21 @@ populate_rti_info(struct sockaddr **rti_info, struct rt_msghdr *rtm)
rti_info[i] = NULL;
}
}
+
+void
+delete_route(int s, int rdomain, struct rt_msghdr *rtm)
+{
+ static int seqno;
+ int rlen;
+
+ rtm->rtm_type = RTM_DELETE;
+ rtm->rtm_tableid = rdomain;
+ rtm->rtm_seq = seqno++;
+
+ rlen = write(s, (char *)rtm, rtm->rtm_msglen);
+ if (rlen == -1) {
+ if (errno != ESRCH)
+ error("RTM_DELETE write: %s", strerror(errno));
+ } else if (rlen < (int)rtm->rtm_msglen)
+ error("short RTM_DELETE write (%d)\n", rlen);
+}