Commit 3982d3d2 authored by Fischer, Anna's avatar Fischer, Anna Committed by David S. Miller
Browse files

net/bridge: Add 'hairpin' port forwarding mode

This patch adds a 'hairpin' (also called 'reflective relay') mode
port configuration to the Linux Ethernet bridge kernel module.
A bridge supporting hairpin forwarding mode can send frames back
out through the port the frame was received on.

Hairpin mode is required to support basic VEPA (Virtual
Ethernet Port Aggregator) capabilities.

You can find additional information on VEPA here:

An additional patch 'bridge-utils: Add 'hairpin' port forwarding mode'
is provided to allow configuring hairpin mode from userspace tools.

Signed-off-by: default avatarPaul Congdon <>
Signed-off-by: default avatarAnna Fischer <>
Acked-by: default avatarArnd Bergmann <>
Signed-off-by: default avatarDavid S. Miller <>
parent 8dd07086
......@@ -22,7 +22,8 @@
static inline int should_deliver(const struct net_bridge_port *p,
const struct sk_buff *skb)
return (skb->dev != p->dev && p->state == BR_STATE_FORWARDING);
return (((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) &&
static inline unsigned packet_length(const struct sk_buff *skb)
......@@ -256,6 +256,7 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
p->path_cost = port_cost(dev);
p->priority = 0x8000 >> BR_PORT_BITS;
p->port_no = index;
p->flags = 0;
......@@ -81,6 +81,9 @@ struct net_bridge_port
struct timer_list message_age_timer;
struct kobject kobj;
struct rcu_head rcu;
unsigned long flags;
#define BR_HAIRPIN_MODE 0x00000001
struct net_bridge
......@@ -143,6 +143,22 @@ static ssize_t store_flush(struct net_bridge_port *p, unsigned long v)
static BRPORT_ATTR(flush, S_IWUSR, NULL, store_flush);
static ssize_t show_hairpin_mode(struct net_bridge_port *p, char *buf)
int hairpin_mode = (p->flags & BR_HAIRPIN_MODE) ? 1 : 0;
return sprintf(buf, "%d\n", hairpin_mode);
static ssize_t store_hairpin_mode(struct net_bridge_port *p, unsigned long v)
if (v)
p->flags |= BR_HAIRPIN_MODE;
p->flags &= ~BR_HAIRPIN_MODE;
return 0;
static BRPORT_ATTR(hairpin_mode, S_IRUGO | S_IWUSR,
show_hairpin_mode, store_hairpin_mode);
static struct brport_attribute *brport_attrs[] = {
......@@ -159,6 +175,7 @@ static struct brport_attribute *brport_attrs[] = {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment