Skip to content

Commit

Permalink
veth: Showing peer of veth type dev in ip link (kernel side)
Browse files Browse the repository at this point in the history
ip link has ability to show extra information of net work device if
kernel provides sunh information. With this patch veth driver can
provide its peer ifindex information to ip command via netlink
interface.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Masatake YAMATO authored and David S. Miller committed Oct 8, 2013
1 parent 33bc801 commit 612c337
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions drivers/net/veth.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,25 @@ static const struct nla_policy veth_policy[VETH_INFO_MAX + 1] = {
[VETH_INFO_PEER] = { .len = sizeof(struct ifinfomsg) },
};

static size_t veth_get_size(const struct net_device *dev)
{
return nla_total_size(sizeof(u64)) + /* VETH_INFO_PEER */
0;
}

static int veth_fill_info(struct sk_buff *skb, const struct net_device *dev)
{
struct veth_priv *priv = netdev_priv(dev);
struct net_device *peer = rtnl_dereference(priv->peer);
u64 peer_ifindex;

peer_ifindex = peer ? peer->ifindex : 0;
if (nla_put_u64(skb, VETH_INFO_PEER, peer_ifindex))
return -EMSGSIZE;

return 0;
}

static struct rtnl_link_ops veth_link_ops = {
.kind = DRV_NAME,
.priv_size = sizeof(struct veth_priv),
Expand All @@ -443,6 +462,8 @@ static struct rtnl_link_ops veth_link_ops = {
.dellink = veth_dellink,
.policy = veth_policy,
.maxtype = VETH_INFO_MAX,
.get_size = veth_get_size,
.fill_info = veth_fill_info,
};

/*
Expand Down

0 comments on commit 612c337

Please sign in to comment.