From 08d7dbbb00d88086147d96438b5702c02b5f3d79 Mon Sep 17 00:00:00 2001 From: dlg Date: Thu, 23 Nov 2023 03:38:34 +0000 Subject: [PATCH] add an endpoint command for "bridges" that use addresses as endpoints. this can be used to add static entries on interfaces like vxlan(4). --- sbin/ifconfig/brconfig.c | 38 +++++++++++++++++++++++++++++++++++++- sbin/ifconfig/ifconfig.c | 3 ++- sbin/ifconfig/ifconfig.h | 3 ++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/sbin/ifconfig/brconfig.c b/sbin/ifconfig/brconfig.c index b82d5d7b3e7..f6a3d0ef619 100644 --- a/sbin/ifconfig/brconfig.c +++ b/sbin/ifconfig/brconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: brconfig.c,v 1.31 2022/07/08 07:04:54 jsg Exp $ */ +/* $OpenBSD: brconfig.c,v 1.32 2023/11/23 03:38:34 dlg Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -656,6 +656,42 @@ bridge_addaddr(const char *ifsname, const char *addr) err(1, "%s: %s", ifname, addr); } +void +bridge_addendpoint(const char *endpoint, const char *addr) +{ + struct ifbareq ifba; + struct ether_addr *ea; + struct addrinfo *res; + int ecode; + + /* should we handle ports? */ + ecode = getaddrinfo(endpoint, NULL, NULL, &res); + if (ecode != 0) { + errx(1, "%s endpoint %s: %s", ifname, endpoint, + gai_strerror(ecode)); + } + if (res->ai_addrlen > sizeof(ifba.ifba_dstsa)) + errx(1, "%s: addrlen > dstsa", __func__); + + ea = ether_aton(addr); + if (ea == NULL) { + errx(1, "%s endpoint %s %s: invalid Ethernet address", + ifname, endpoint, addr); + } + + memset(&ifba, 0, sizeof(ifba)); + strlcpy(ifba.ifba_name, ifname, sizeof(ifba.ifba_name)); + strlcpy(ifba.ifba_ifsname, ifname, sizeof(ifba.ifba_ifsname)); + memcpy(&ifba.ifba_dst, ea, sizeof(struct ether_addr)); + memcpy(&ifba.ifba_dstsa, res->ai_addr, res->ai_addrlen); + ifba.ifba_flags = IFBAF_STATIC; + + freeaddrinfo(res); + + if (ioctl(sock, SIOCBRDGSADDR, &ifba) == -1) + err(1, "%s endpoint %s %s", ifname, endpoint, addr); +} + void bridge_addrs(const char *delim, int d) { diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 6d8a90209ff..8310907e9f7 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.469 2023/11/23 03:22:14 dlg Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.470 2023/11/23 03:38:34 dlg Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -577,6 +577,7 @@ const struct cmd { { "flush", 0, 0, bridge_flush }, { "flushall", 0, 0, bridge_flushall }, { "static", NEXTARG2, 0, NULL, bridge_addaddr }, + { "endpoint", NEXTARG2, 0, NULL, bridge_addendpoint }, { "deladdr", NEXTARG, 0, bridge_deladdr }, { "maxaddr", NEXTARG, 0, bridge_maxaddr }, { "addr", 0, 0, bridge_addrs }, diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index 806a5e639cb..7df268f46bf 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.h,v 1.4 2021/11/11 09:39:16 claudio Exp $ */ +/* $OpenBSD: ifconfig.h,v 1.5 2023/11/23 03:38:34 dlg Exp $ */ /* * Copyright (c) 2009 Claudio Jeker @@ -48,6 +48,7 @@ void bridge_delspan(const char *, int); void bridge_flush(const char *, int); void bridge_flushall(const char *, int); void bridge_addaddr(const char *, const char *); +void bridge_addendpoint(const char *, const char *); void bridge_deladdr(const char *, int); void bridge_maxaddr(const char *, int); void bridge_addrs(const char *, int); -- 2.20.1