diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2004-06-26 17:36:34 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2004-06-26 17:36:34 +0000 |
commit | a3223076fbcf9fd0445a492f0e5a991836205eb6 (patch) | |
tree | 3e0d60b021e41b9f31170ac400ccb23536bf2657 | |
parent | ddf23390e0f682aa4e8ca6bcdc980d76b6cff1e1 (diff) |
cleanup ioctl for ifgroups; ok pb@
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 56 | ||||
-rw-r--r-- | sys/net/if.c | 43 | ||||
-rw-r--r-- | sys/net/if.h | 23 |
3 files changed, 57 insertions, 65 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 3d586a4332f..604f92f030d 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.107 2004/06/26 06:59:17 alex Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.108 2004/06/26 17:36:33 markus Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -77,7 +77,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; #else -static const char rcsid[] = "$OpenBSD: ifconfig.c,v 1.107 2004/06/26 06:59:17 alex Exp $"; +static const char rcsid[] = "$OpenBSD: ifconfig.c,v 1.108 2004/06/26 17:36:33 markus Exp $"; #endif #endif /* not lint */ @@ -1050,32 +1050,28 @@ setifmtu(const char *val, int d) void setifgroup(const char *group_name, int dummy) { - struct ifgroupreq ifg; + struct ifgroupreq ifgr; - memset(&ifg, 0, sizeof(ifg)); + memset(&ifgr, 0, sizeof(ifgr)); + strlcpy(ifgr.ifgr_name, name, IFNAMSIZ); - strlcpy(ifg.if_name, name, IFNAMSIZ); - - if (strlcpy(ifg.ifg_group, group_name, IFNAMSIZ) >= IFNAMSIZ) + if (strlcpy(ifgr.ifgr_group, group_name, IFNAMSIZ) >= IFNAMSIZ) err(1, "setifgroup: group name too long"); - - if (ioctl(s, SIOCAIFGROUP, (caddr_t)&ifg) == -1) + if (ioctl(s, SIOCAIFGROUP, (caddr_t)&ifgr) == -1) err(1," SIOCAIFGROUP"); } void unsetifgroup(const char *group_name, int dummy) { - struct ifgroupreq ifg; + struct ifgroupreq ifgr; - memset(&ifg, 0, sizeof(ifg)); + memset(&ifgr, 0, sizeof(ifgr)); + strlcpy(ifgr.ifgr_name, name, IFNAMSIZ); - strlcpy(ifg.if_name, name, IFNAMSIZ); - - if (strlcpy(ifg.ifg_group, group_name, IFNAMSIZ) >= IFNAMSIZ) + if (strlcpy(ifgr.ifgr_group, group_name, IFNAMSIZ) >= IFNAMSIZ) err(1, "unsetifgroup: group name too long"); - - if (ioctl(s, SIOCDIFGROUP, (caddr_t)&ifg) == -1) + if (ioctl(s, SIOCDIFGROUP, (caddr_t)&ifgr) == -1) err(1, "SIOCDIFGROUP"); } @@ -2650,38 +2646,38 @@ void getifgroups(void) { int len; - struct ifgroupreq ifg; - struct ifgroup *ifgp; + struct ifgroupreq ifgr; + struct ifgroup *ifg; - memset(&ifg, 0, sizeof(ifg)); - strlcpy(ifg.if_name, name, IFNAMSIZ); + memset(&ifgr, 0, sizeof(ifgr)); + strlcpy(ifgr.ifgr_name, name, IFNAMSIZ); - if (ioctl(s, SIOCGIFGROUP, (caddr_t)&ifg) == -1) + if (ioctl(s, SIOCGIFGROUP, (caddr_t)&ifgr) == -1) if (errno == EINVAL || errno == ENOTTY) return; else err(1, "SIOCGIFGROUP"); - len = ifg.ifg_len; - ifg.ifg_groups = (struct ifgroup *)calloc(len / sizeof(struct ifgroup), + len = ifgr.ifgr_len; + ifgr.ifgr_groups = (struct ifgroup *)calloc(len / sizeof(struct ifgroup), sizeof(struct ifgroup)); - if (ifg.ifg_groups == NULL) + if (ifgr.ifgr_groups == NULL) err(1, "getifgroups"); - if (ioctl(s, SIOCGIFGROUP, (caddr_t)&ifg) == -1) + if (ioctl(s, SIOCGIFGROUP, (caddr_t)&ifgr) == -1) err(1, "SIOCGIFGROUP"); if (len -= sizeof(struct ifgroup)) { len += sizeof(struct ifgroup); printf("\tgroups: "); - ifgp = ifg.ifg_groups; - if (ifgp) { + ifg = ifgr.ifgr_groups; + if (ifg) { len -= sizeof(struct ifgroup); - ifgp++; + ifg++; } - for (; ifgp && len >= sizeof(struct ifgroup); ifgp++) { + for (; ifg && len >= sizeof(struct ifgroup); ifg++) { len -= sizeof(struct ifgroup); - printf("%s ", ifgp->if_group); + printf("%s ", ifg->ifg_group); } printf("\n"); } diff --git a/sys/net/if.c b/sys/net/if.c index de1e3ced9f6..040733bdfa3 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.89 2004/06/25 18:24:23 pb Exp $ */ +/* $OpenBSD: if.c,v 1.90 2004/06/26 17:36:32 markus Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -248,8 +248,8 @@ if_attachsetup(ifp) ifp->if_xname[n] < '0' || ifp->if_xname[n] > '9'; n++) continue; - strlcpy(ifg->if_group, ifp->if_xname, n + 1); - TAILQ_INSERT_HEAD(&ifp->if_groups, ifg, group_list); + strlcpy(ifg->ifg_group, ifp->if_xname, n + 1); + TAILQ_INSERT_HEAD(&ifp->if_groups, ifg, ifg_next); } ifindex2ifnet[if_index] = ifp; @@ -596,7 +596,7 @@ do { \ for (ifg = TAILQ_FIRST(&ifp->if_groups); ifg; ifg = TAILQ_FIRST(&ifp->if_groups)) { - TAILQ_REMOVE(&ifp->if_groups, ifg, group_list); + TAILQ_REMOVE(&ifp->if_groups, ifg, ifg_next); free(ifg, M_TEMP); } @@ -1501,20 +1501,20 @@ if_detached_watchdog(struct ifnet *ifp) * Add a group to an interface */ int -if_addgroup(struct ifgroupreq *ifg, struct ifnet *ifp) +if_addgroup(struct ifgroupreq *ifgr, struct ifnet *ifp) { struct ifgroup *ifgnew, *ifgp; - TAILQ_FOREACH(ifgp, &ifp->if_groups, group_list) - if (!strcmp(ifgp->if_group, ifg->ifg_group)) + TAILQ_FOREACH(ifgp, &ifp->if_groups, ifg_next) + if (!strcmp(ifgp->ifg_group, ifgr->ifgr_group)) return (EEXIST); ifgnew = (struct ifgroup *)malloc(sizeof(struct ifgroup), M_TEMP, M_NOWAIT); if (ifgnew == NULL) return (ENOMEM); - strlcpy(ifgnew->if_group, ifg->ifg_group, IFNAMSIZ); - TAILQ_INSERT_TAIL(&ifp->if_groups, ifgnew, group_list); + strlcpy(ifgnew->ifg_group, ifgr->ifgr_group, IFNAMSIZ); + TAILQ_INSERT_TAIL(&ifp->if_groups, ifgnew, ifg_next); return (0); } @@ -1524,23 +1524,22 @@ if_addgroup(struct ifgroupreq *ifg, struct ifnet *ifp) * note: the first group is the if-family - do not remove */ int -if_delgroup(struct ifgroupreq *ifg, struct ifnet *ifp) +if_delgroup(struct ifgroupreq *ifgr, struct ifnet *ifp) { struct ifgroup *ifgp; for (ifgp = TAILQ_FIRST(&ifp->if_groups); ifgp != TAILQ_END(&ifp->if_groups); - ifgp = TAILQ_NEXT(ifgp, group_list)) { + ifgp = TAILQ_NEXT(ifgp, ifg_next)) { if (ifgp == TAILQ_FIRST(&ifp->if_groups) && - !strcmp(ifgp->if_group, ifg->ifg_group)) + !strcmp(ifgp->ifg_group, ifgr->ifgr_group)) return (EPERM); - if (!strcmp(ifgp->if_group, ifg->ifg_group)) { - TAILQ_REMOVE(&ifp->if_groups, ifgp, group_list); + if (!strcmp(ifgp->ifg_group, ifgr->ifgr_group)) { + TAILQ_REMOVE(&ifp->if_groups, ifgp, ifg_next); free(ifgp, M_TEMP); return (0); } } - return (ENOENT); } @@ -1556,19 +1555,19 @@ if_getgroup(caddr_t data, struct ifnet *ifp) struct ifgroup *ifgp, *ifgp2, ifg; struct ifgroupreq *ifgr = (struct ifgroupreq *)data; - if (ifgr->ifg_len == 0) { - TAILQ_FOREACH(ifgp, &ifp->if_groups, group_list) - ifgr->ifg_len += sizeof(struct ifgroup); + if (ifgr->ifgr_len == 0) { + TAILQ_FOREACH(ifgp, &ifp->if_groups, ifg_next) + ifgr->ifgr_len += sizeof(struct ifgroup); return (0); } - len = ifgr->ifg_len; - ifgp = ifgr->ifg_groups; + len = ifgr->ifgr_len; + ifgp = ifgr->ifgr_groups; for (ifgp2 = TAILQ_FIRST(&ifp->if_groups); ifgp2 && len >= sizeof(struct ifgroup); - ifgp2 = TAILQ_NEXT(ifgp2, group_list)) { + ifgp2 = TAILQ_NEXT(ifgp2, ifg_next)) { memset(&ifg, 0, sizeof(struct ifgroup)); - strlcpy(ifg.if_group, ifgp2->if_group, IFNAMSIZ); + strlcpy(ifg.ifg_group, ifgp2->ifg_group, IFNAMSIZ); error = copyout((caddr_t)&ifg, (caddr_t)ifgp, sizeof(struct ifgroup)); if (error) diff --git a/sys/net/if.h b/sys/net/if.h index ebcf9625a51..5d067e288ec 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if.h,v 1.55 2004/06/25 18:24:23 pb Exp $ */ +/* $OpenBSD: if.h,v 1.56 2004/06/26 17:36:33 markus Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -401,25 +401,22 @@ struct if_announcemsghdr { * The groups on an interface */ struct ifgroup { - char if_group[IFNAMSIZ]; - TAILQ_ENTRY(ifgroup) group_list; + char ifg_group[IFNAMSIZ]; + TAILQ_ENTRY(ifgroup) ifg_next; }; /* * Used to lookup groups for an interface */ struct ifgroupreq { - char if_name[IFNAMSIZ]; - u_int ifg_len; - + char ifgr_name[IFNAMSIZ]; + u_int ifgr_len; union { - char if_group[IFNAMSIZ]; - struct ifgroup *ifg; - } ifg_ifgu; - - TAILQ_ENTRY(ifgroupreq) next_if; -#define ifg_group ifg_ifgu.if_group -#define ifg_groups ifg_ifgu.ifg + char ifgru_group[IFNAMSIZ]; + struct ifgroup *ifgru_groups; + } ifgr_ifgru; +#define ifgr_group ifgr_ifgru.ifgru_group +#define ifgr_groups ifgr_ifgru.ifgru_groups }; /* |