Skip to content

Commit

Permalink
mpls: Per-device enabling of packet input
Browse files Browse the repository at this point in the history
An MPLS network is a single trust domain where the edges must be in
control of what labels make their way into the core. The simplest way
of ensuring this is for the edge device to always impose the labels,
and not allow forward labeled traffic from untrusted neighbours. This
is achieved by allowing a per-device configuration of whether MPLS
traffic input from that interface should be processed or not.

To be secure by default, the default state is changed to MPLS being
disabled on all interfaces unless explicitly enabled and no global
option is provided to change the default. Whilst this differs from
other protocols (e.g. IPv6), network operators are used to explicitly
enabling MPLS forwarding on interfaces, and with the number of links
to the MPLS core typically fairly low this doesn't present too much of
a burden on operators.

Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Robert Shearman <rshearma@brocade.com>
Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
rshearman authored and davem330 committed Apr 22, 2015
1 parent 03c5774 commit 37bde79
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Documentation/networking/mpls-sysctl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ platform_labels - INTEGER

Possible values: 0 - 1048575
Default: 0

conf/<interface>/input - BOOL
Control whether packets can be input on this interface.

If disabled, packets will be discarded without further
processing.

0 - disabled (default)
not 0 - enabled
68 changes: 66 additions & 2 deletions net/mpls/af_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
/* Careful this entire function runs inside of an rcu critical section */

mdev = mpls_dev_get(dev);
if (!mdev)
if (!mdev || !mdev->input_enabled)
goto drop;

if (skb->pkt_type != PACKET_HOST)
Expand Down Expand Up @@ -438,6 +438,60 @@ static int mpls_route_del(struct mpls_route_config *cfg)
return err;
}

#define MPLS_PERDEV_SYSCTL_OFFSET(field) \
(&((struct mpls_dev *)0)->field)

static const struct ctl_table mpls_dev_table[] = {
{
.procname = "input",
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec,
.data = MPLS_PERDEV_SYSCTL_OFFSET(input_enabled),
},
{ }
};

static int mpls_dev_sysctl_register(struct net_device *dev,
struct mpls_dev *mdev)
{
char path[sizeof("net/mpls/conf/") + IFNAMSIZ];
struct ctl_table *table;
int i;

table = kmemdup(&mpls_dev_table, sizeof(mpls_dev_table), GFP_KERNEL);
if (!table)
goto out;

/* Table data contains only offsets relative to the base of
* the mdev at this point, so make them absolute.
*/
for (i = 0; i < ARRAY_SIZE(mpls_dev_table); i++)
table[i].data = (char *)mdev + (uintptr_t)table[i].data;

snprintf(path, sizeof(path), "net/mpls/conf/%s", dev->name);

mdev->sysctl = register_net_sysctl(dev_net(dev), path, table);
if (!mdev->sysctl)
goto free;

return 0;

free:
kfree(table);
out:
return -ENOBUFS;
}

static void mpls_dev_sysctl_unregister(struct mpls_dev *mdev)
{
struct ctl_table *table;

table = mdev->sysctl->ctl_table_arg;
unregister_net_sysctl_table(mdev->sysctl);
kfree(table);
}

static struct mpls_dev *mpls_add_dev(struct net_device *dev)
{
struct mpls_dev *mdev;
Expand All @@ -449,9 +503,17 @@ static struct mpls_dev *mpls_add_dev(struct net_device *dev)
if (!mdev)
return ERR_PTR(err);

err = mpls_dev_sysctl_register(dev, mdev);
if (err)
goto free;

rcu_assign_pointer(dev->mpls_ptr, mdev);

return mdev;

free:
kfree(mdev);
return ERR_PTR(err);
}

static void mpls_ifdown(struct net_device *dev)
Expand All @@ -475,6 +537,8 @@ static void mpls_ifdown(struct net_device *dev)
if (!mdev)
return;

mpls_dev_sysctl_unregister(mdev);

RCU_INIT_POINTER(dev->mpls_ptr, NULL);

kfree(mdev);
Expand Down Expand Up @@ -958,7 +1022,7 @@ static int mpls_platform_labels(struct ctl_table *table, int write,
return ret;
}

static struct ctl_table mpls_table[] = {
static const struct ctl_table mpls_table[] = {
{
.procname = "platform_labels",
.data = NULL,
Expand Down
3 changes: 3 additions & 0 deletions net/mpls/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct mpls_entry_decoded {
};

struct mpls_dev {
int input_enabled;

struct ctl_table_header *sysctl;
};

struct sk_buff;
Expand Down

0 comments on commit 37bde79

Please sign in to comment.