Skip to content

Commit b3f35c3

Browse files
committed
Add support for multiple VLANs on same interface
A common case is to have multiple VLANs on a bridge, in such setups we want to treat each VLAN as if we run in proxy-mode on a VLAN interface on top of the bridge. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent c0655be commit b3f35c3

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/cfparse.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ ifmod : DISABLE { ifi->ifi_flags |= IFIF_DISABLED; }
164164
{
165165
if ($2 < 1 || $2 > 4094)
166166
fatal("Invalid VLAN ID [1,4094]");
167-
ifi->ifi_vlan = $2;
167+
ifi = config_iface_vlan(ifi, $2);
168168
}
169169
;
170170

src/config.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,31 @@ struct ifi *config_iface_add(char *ifname)
138138
return ifi;
139139
}
140140

141+
/*
142+
* Called by parser for 'vlan NUM', may create an interface clone of
143+
* the current interface with already learned settings.
144+
*/
145+
struct ifi *config_iface_vlan(struct ifi *ifi, int vid)
146+
{
147+
struct ifi *clone;
148+
149+
if (ifi->ifi_vlan == 0) {
150+
ifi->ifi_vlan = vid;
151+
return ifi;
152+
}
153+
154+
clone = malloc(sizeof(*clone));
155+
if (!clone)
156+
logit(LOG_ERR, errno, "failed cloning %s for new VLAN %d", ifi->ifi_name, vid);
157+
158+
memcpy(clone, ifi, sizeof(*clone));
159+
TAILQ_INSERT_TAIL(&ifaces, clone, ifi_link);
160+
161+
clone->ifi_vlan = vid;
162+
163+
return clone;
164+
}
165+
141166
static struct ifi *addr_add(int ifindex, struct sockaddr *sa, unsigned int flags)
142167
{
143168
struct sockaddr_in *sin = (struct sockaddr_in *)sa;

src/defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ extern void config_init(void);
160160
extern void config_set_ifflag(uint32_t);
161161
extern struct ifi *config_iface_iter(int);
162162
extern struct ifi *config_iface_add(char *);
163+
extern struct ifi *config_iface_vlan(struct ifi *, int);
163164
extern void config_iface_addr_del(int, struct sockaddr *);
164165
extern struct ifi *config_find_ifname(char *);
165166
extern struct ifi *config_find_ifaddr(in_addr_t);

0 commit comments

Comments
 (0)