Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F132954833
D17522.id49024.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D17522.id49024.diff
View Options
Index: lib/libifconfig/Makefile
===================================================================
--- lib/libifconfig/Makefile
+++ lib/libifconfig/Makefile
@@ -8,9 +8,9 @@
SHLIBDIR?= /lib
SHLIB_MAJOR= 1
-SRCS= libifconfig.c libifconfig_carp.c libifconfig_inet.c
-SRCS+= libifconfig_inet6.c libifconfig_internal.c libifconfig_lagg.c
-SRCS+= libifconfig_media.c
+SRCS= libifconfig.c libifconfig_bridge.c libifconfig_carp.c
+SRCS+= libifconfig_inet.c libifconfig_inet6.c libifconfig_internal.c
+SRCS+= libifconfig_lagg.c libifconfig_media.c
INCSDIR= ${INCLUDEDIR}
INCS= libifconfig.h
Index: lib/libifconfig/libifconfig.h
===================================================================
--- lib/libifconfig/libifconfig.h
+++ lib/libifconfig/libifconfig.h
@@ -238,14 +238,14 @@
/** Creates a (virtual) interface
* @param name Name of interface to create. Example: bridge or bridge42
- * @param name ifname Is set to actual name of created interface
+ * @param ifname Is set to actual name of created interface
*/
int ifconfig_create_interface(ifconfig_handle_t *h, const char *name,
char **ifname);
/** Creates a (virtual) interface
* @param name Name of interface to create. Example: vlan0 or ix0.50
- * @param name ifname Is set to actual name of created interface
+ * @param ifname ifname Is set to actual name of created interface
* @param vlandev Name of interface to attach to
* @param vlanid VLAN ID/Tag. Must not be 0.
*/
@@ -254,3 +254,17 @@
int ifconfig_set_vlantag(ifconfig_handle_t *h, const char *name,
const char *vlandev, const unsigned short vlantag);
+
+/** Adds interface to bridge
+ * @param name Name of bridge
+ * @param membername Name of interface to add as member of bridge
+ */
+int ifconfig_bridge_add_member(ifconfig_handle_t *h, const char *name,
+ const char *membername);
+
+/** Adds interface to bridge
+ * @param name Name of bridge
+ * @param membername Name of interface to remove from bridge
+ */
+int ifconfig_bridge_remove_member(ifconfig_handle_t *h, const char *name,
+ const char *membername);
Index: lib/libifconfig/libifconfig_bridge.c
===================================================================
--- /dev/null
+++ lib/libifconfig/libifconfig_bridge.c
@@ -0,0 +1,99 @@
+/*-
+ * SPDX-License-Identifier: BSD-4-Clause
+ *
+ * Copyright 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include <sys/sockio.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_bridgevar.h>
+
+#include <string.h>
+
+#include "libifconfig.h"
+#include "libifconfig_internal.h"
+
+static int
+do_cmd(ifconfig_handle_t *h, const char *bridgename, u_long op, void *arg, size_t argsize, int set)
+{
+ struct ifdrv ifd;
+
+ memset(&ifd, 0, sizeof(ifd));
+
+ strlcpy(ifd.ifd_name, bridgename, sizeof(ifd.ifd_name));
+ ifd.ifd_cmd = op;
+ ifd.ifd_len = argsize;
+ ifd.ifd_data = arg;
+
+ return (ifconfig_ioctlwrap(h, AF_LOCAL, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd));
+}
+
+// TODO: Consider merging _add_member and _remove_member
+
+int ifconfig_bridge_add_member(ifconfig_handle_t *h, const char *name,
+ const char *membername)
+{
+ struct ifbreq req;
+
+ memset(&req, 0, sizeof(req));
+
+ strlcpy(req.ifbr_ifsname, membername, sizeof(req.ifbr_ifsname));
+
+ if (do_cmd(h, name, BRDGADD, &req, sizeof(req), 1) < 0) {
+ return (-1);
+ }
+ return 0;
+}
+
+int ifconfig_bridge_remove_member(ifconfig_handle_t *h, const char *name,
+ const char *membername)
+{
+ struct ifbreq req;
+
+ memset(&req, 0, sizeof(req));
+
+ strlcpy(req.ifbr_ifsname, membername, sizeof(req.ifbr_ifsname));
+
+ if (do_cmd(h, name, BRDGDEL, &req, sizeof(req), 1) < 0) {
+ return (-1);
+ }
+ return 0;
+}
+
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Oct 22, 12:17 PM (13 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
24056231
Default Alt Text
D17522.id49024.diff (5 KB)
Attached To
Mode
D17522: libifconfig: Add initial support for if_bridge
Attached
Detach File
Event Timeline
Log In to Comment