summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2006-11-16 13:09:28 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2006-11-16 13:09:28 +0000
commitd8d2a56520b9d0b29c80ccc2e8cbdd14fa299ef0 (patch)
tree645381c8303f28e8e55f73bf3f5ab831a5b7abda /sys
parent9f759c2a2fd538246c3c6e3ffc0a14d0c8b0ab64 (diff)
introduce if_creategroup() to create an empty interface group.
code factored out from if_addgroup(), previously a group always had to have members. ok mpf mcbride
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if.c45
-rw-r--r--sys/net/if.h3
2 files changed, 31 insertions, 17 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index bf856c8db61..56238f8350e 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.150 2006/10/21 14:02:11 henning Exp $ */
+/* $OpenBSD: if.c,v 1.151 2006/11/16 13:09:27 henning Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -1560,6 +1560,30 @@ if_detached_watchdog(struct ifnet *ifp)
}
/*
+ * Create interface group without members
+ */
+struct ifg_group *
+if_creategroup(const char *groupname)
+{
+ struct ifg_group *ifg = NULL;
+
+ if ((ifg = (struct ifg_group *)malloc(sizeof(struct ifg_group),
+ M_TEMP, M_NOWAIT)) == NULL)
+ return (NULL);
+
+ strlcpy(ifg->ifg_group, groupname, sizeof(ifg->ifg_group));
+ ifg->ifg_refcnt = 0;
+ ifg->ifg_carp_demoted = 0;
+ TAILQ_INIT(&ifg->ifg_members);
+#if NPF > 0
+ pfi_attach_ifgroup(ifg);
+#endif
+ TAILQ_INSERT_TAIL(&ifg_head, ifg, ifg_next);
+
+ return (ifg);
+}
+
+/*
* Add a group to an interface
*/
int
@@ -1591,21 +1615,10 @@ if_addgroup(struct ifnet *ifp, const char *groupname)
if (!strcmp(ifg->ifg_group, groupname))
break;
- if (ifg == NULL) {
- if ((ifg = (struct ifg_group *)malloc(sizeof(struct ifg_group),
- M_TEMP, M_NOWAIT)) == NULL) {
- free(ifgl, M_TEMP);
- free(ifgm, M_TEMP);
- return (ENOMEM);
- }
- strlcpy(ifg->ifg_group, groupname, sizeof(ifg->ifg_group));
- ifg->ifg_refcnt = 0;
- ifg->ifg_carp_demoted = 0;
- TAILQ_INIT(&ifg->ifg_members);
-#if NPF > 0
- pfi_attach_ifgroup(ifg);
-#endif
- TAILQ_INSERT_TAIL(&ifg_head, ifg, ifg_next);
+ if (ifg == NULL && (ifg = if_creategroup(groupname)) == NULL) {
+ free(ifgl, M_TEMP);
+ free(ifgm, M_TEMP);
+ return (ENOMEM);
}
ifg->ifg_refcnt++;
diff --git a/sys/net/if.h b/sys/net/if.h
index 900a2039719..ddc6f8d76a8 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.83 2006/10/31 14:28:29 jason Exp $ */
+/* $OpenBSD: if.h,v 1.84 2006/11/16 13:09:27 henning Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -702,6 +702,7 @@ int ifconf(u_long, caddr_t);
void ifinit(void);
int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
int ifpromisc(struct ifnet *, int);
+struct ifg_group *if_creategroup(const char *);
int if_addgroup(struct ifnet *, const char *);
int if_delgroup(struct ifnet *, const char *);
void if_group_routechange(struct sockaddr *, struct sockaddr *);