Skip to content

Commit

Permalink
add the option of 'vnetid any' for multipoint-to-multipoint mode in v…
Browse files Browse the repository at this point in the history
…xlan
  • Loading branch information
yellowman committed May 1, 2021
1 parent 7624bf7 commit 92b589f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
7 changes: 5 additions & 2 deletions conf.c
Expand Up @@ -599,10 +599,13 @@ int conf_ifaddr_dhcp(FILE *output, char *ifname, int flags)

void conf_vnetid(FILE *output, int ifs, char *ifname)
{
int vnetid;
int64_t vnetid;

if (((vnetid = get_vnetid(ifs, ifname)) != 0))
fprintf(output, " vnetid %i\n", vnetid);
if (vnetid < 0)
fprintf(output, " vnetid any\n", vnetid);
else
fprintf(output, " vnetid %lld\n", vnetid);
}

void conf_patch(FILE *output, int ifs, char *ifname)
Expand Down
2 changes: 1 addition & 1 deletion externs.h
Expand Up @@ -448,7 +448,7 @@ int inttunnel(char *, int, int, char **);
int intvnetid(char *, int, int, char **);
int get_physrtable(int, char *);
int get_physttl(int, char *);
int get_vnetid(int, char *);
int64_t get_vnetid(int, char *);

/* media.c */
#define DEFAULT_MEDIA_TYPE "autoselect"
Expand Down
22 changes: 13 additions & 9 deletions tunnel.c
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
Expand Down Expand Up @@ -245,24 +246,27 @@ void
setvnetid(int ifs, char *ifname, char *vnetida)
{
const char *errmsg = NULL;
int vnetid;
int64_t vnetid;
struct ifreq ifr;

if (vnetida == NULL)
return;

/* vxlan 2^24 is the upper limit user of vnetid as of OpenBSD 6.0 */
vnetid = strtonum(vnetida, 0, 0xffffff, &errmsg);
if (errmsg) {
printf("%% vnetid %s out of range for %s: %s\n", vnetida,
ifname, errmsg);
return;
if (isprefix("any", vnetida)) {
vnetid = -1;
} else {
vnetid = strtonum(vnetida, 0, INT64_MAX, &errmsg);
if (errmsg) {
printf("%% vnetid %s out of range: %s\n", vnetida,
errmsg);
return;
}
}
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
ifr.ifr_vnetid = vnetid;
if (ioctl(ifs, SIOCSVNETID, (caddr_t)&ifr) < 0) {
if (errno == EINVAL) {
printf("%% vnetid %d out of range for %s\n",
printf("%% vnetid %lld out of range for %s\n",
vnetid, ifname);
} else {
printf("%% setvnetid SIOCSVNETID: %s\n",
Expand Down Expand Up @@ -321,7 +325,7 @@ int get_physttl(int s, char *ifname)
return ifr.ifr_ttl;
}

int get_vnetid(int s, char *ifname)
int64_t get_vnetid(int s, char *ifname)
{
struct ifreq ifr;

Expand Down

0 comments on commit 92b589f

Please sign in to comment.