Skip to content

Commit

Permalink
add an endpoint command for "bridges" that use addresses as endpoints.
Browse files Browse the repository at this point in the history
this can be used to add static entries on interfaces like vxlan(4).
  • Loading branch information
dlg committed Nov 23, 2023
1 parent b99a4db commit 08d7dbb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
38 changes: 37 additions & 1 deletion 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)
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion 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 $ */

/*
Expand Down Expand Up @@ -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 },
Expand Down
3 changes: 2 additions & 1 deletion 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>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 08d7dbb

Please sign in to comment.