Skip to content

Commit ad1c3cb

Browse files
committed
FreeBSD: Introduce vlan-pcp option for VLAN PCP tagging
1 parent 4dd7ebe commit ad1c3cb

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/bpf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ bpf_open(const struct interface *ifp,
162162
#ifdef BIOCIMMEDIATE
163163
unsigned int flags;
164164
#endif
165+
#ifdef BIOCSETVLANPCP
166+
u_int vlan_pcp;
167+
#endif
165168
#ifndef O_CLOEXEC
166169
int fd_opts;
167170
#endif
@@ -207,6 +210,14 @@ bpf_open(const struct interface *ifp,
207210
if (ioctl(bpf->bpf_fd, BIOCSETIF, &ifr) == -1)
208211
goto eexit;
209212

213+
#ifdef BIOCSETVLANPCP
214+
if (ifp->options->vlan_pcp > -1) {
215+
vlan_pcp = (u_int)ifp->options->vlan_pcp;
216+
if (ioctl(bpf->bpf_fd, BIOCSETVLANPCP, &vlan_pcp) == -1)
217+
goto eexit;
218+
}
219+
#endif
220+
210221
#ifdef BIOCIMMEDIATE
211222
flags = 1;
212223
if (ioctl(bpf->bpf_fd, BIOCIMMEDIATE, &flags) == -1)

src/if-options.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <sys/types.h>
3131

3232
#include <arpa/inet.h>
33+
#include <net/bpf.h>
3334

3435
#include <ctype.h>
3536
#include <errno.h>
@@ -176,6 +177,9 @@ const struct option cf_options[] = {
176177
{"fallback_time", required_argument, NULL, O_FALLBACK_TIME},
177178
{"ipv4ll_time", required_argument, NULL, O_IPV4LL_TIME},
178179
{"nosyslog", no_argument, NULL, O_NOSYSLOG},
180+
#ifdef BIOCSETVLANPCP
181+
{"vlan-pcp", required_argument, NULL, O_VLANPCP},
182+
#endif
179183
{NULL, 0, NULL, '\0'}
180184
};
181185

@@ -2571,6 +2575,16 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
25712575
logsetopts(logopts);
25722576
}
25732577
break;
2578+
#ifdef BIOCSETVLANPCP
2579+
case O_VLANPCP:
2580+
ARG_REQUIRED;
2581+
ifo->vlan_pcp =
2582+
(int)strtoi(arg, NULL, 0, 0, VLAN_PCP_MAX, &e);
2583+
if (e) {
2584+
logerrx("invalid vlan-pcp: %s", arg);
2585+
return -1;
2586+
}
2587+
#endif
25742588
default:
25752589
return 0;
25762590
}
@@ -2666,6 +2680,11 @@ default_config(struct dhcpcd_ctx *ctx)
26662680
TAILQ_INIT(&ifo->auth.tokens);
26672681
#endif
26682682

2683+
#ifdef BIOCSETVLANPCP
2684+
/* Disable PCP tagging */
2685+
ifo->vlan_pcp = -1;
2686+
#endif
2687+
26692688
/* Inherit some global defaults */
26702689
if (ctx->options & DHCPCD_CONFIGURE)
26712690
ifo->options |= DHCPCD_CONFIGURE;

src/if-options.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <sys/socket.h>
3434
#include <net/if.h>
3535
#include <netinet/in.h>
36+
#include <net/bpf.h>
3637

3738
#include <getopt.h>
3839
#include <limits.h>
@@ -190,6 +191,9 @@
190191
#define O_VSIO O_BASE + 57
191192
#define O_VSIO6 O_BASE + 58
192193
#define O_NOSYSLOG O_BASE + 59
194+
#ifdef BIOCSETVLANPCP
195+
#define O_VLANPCP O_BASE + 60
196+
#endif
193197

194198
extern const struct option cf_options[];
195199

@@ -313,6 +317,10 @@ struct if_options {
313317
#endif
314318

315319
struct auth auth;
320+
321+
#ifdef BIOCSETVLANPCP
322+
int vlan_pcp;
323+
#endif
316324
};
317325

318326
struct if_options *read_config(struct dhcpcd_ctx *,

src/if.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ typedef unsigned long ioctl_request_t;
7373
#include "ipv6.h"
7474
#include "route.h"
7575

76+
#define VLAN_PCP_MAX 7
77+
7678
#define EUI64_ADDR_LEN 8
7779
#define INFINIBAND_ADDR_LEN 20
7880

0 commit comments

Comments
 (0)