Index: lib/libifconfig/Makefile =================================================================== --- lib/libifconfig/Makefile +++ lib/libifconfig/Makefile @@ -8,8 +8,14 @@ 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= +SRCS+= libifconfig.c +SRCS+= libifconfig_bridge.c +SRCS+= libifconfig_carp.c +SRCS+= libifconfig_inet.c +SRCS+= libifconfig_inet6.c +SRCS+= libifconfig_internal.c +SRCS+= libifconfig_lagg.c SRCS+= libifconfig_media.c INCSDIR= ${INCLUDEDIR} 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 + +#include +#include + +#include +#include +#include + +#include + +#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)); +} + +static int +ifconfig_bridge_addrem_member(ifconfig_handle_t *h, const char *name, + const char *membername, int add) +{ + struct ifbreq req; + + memset(&req, 0, sizeof(req)); + + strlcpy(req.ifbr_ifsname, membername, sizeof(req.ifbr_ifsname)); + + if (do_cmd(h, name, add ? BRDGADD : BRDGDEL, &req, + sizeof(req), 1) < 0) + { + return (-1); + } + return 0; +} + +int ifconfig_bridge_add_member(ifconfig_handle_t *h, const char *name, + const char *membername) +{ + return ifconfig_bridge_addrem_member(h, name, membername, 1); +} + +int ifconfig_bridge_remove_member(ifconfig_handle_t *h, const char *name, + const char *membername) +{ + return ifconfig_bridge_addrem_member(h, name, membername, 0); +} +