summaryrefslogtreecommitdiff
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2023-11-23 03:38:35 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2023-11-23 03:38:35 +0000
commitba4a58d94aa3f588b25036f22ad8780867b2309b (patch)
treeb945d7c98cc0841ff49ab2e6cf037d396198a574 /sbin/ifconfig
parente575b37c63ec726c6493ed8972cf4325fc5a3767 (diff)
add an endpoint command for "bridges" that use addresses as endpoints.
this can be used to add static entries on interfaces like vxlan(4).
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/brconfig.c38
-rw-r--r--sbin/ifconfig/ifconfig.c3
-rw-r--r--sbin/ifconfig/ifconfig.h3
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)
@@ -657,6 +657,42 @@ bridge_addaddr(const char *ifsname, const char *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)
{
char dstaddr[NI_MAXHOST];
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 <claudio@openbsd.org>
@@ -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);