This is to be used by an implementation of MSS clamping which requires access to the mtu of interfaces.
Cc: Jesse Gross <je...@nicira.com> Cc: Kyle Mestery <kmest...@cisco.com> Signed-off-by: Simon Horman <ho...@verge.net.au> --- * v5 Initial posting --- lib/route-table.c | 53 ++++++++++++++++++++++++++++++++++++++++++----------- lib/route-table.h | 1 + 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/lib/route-table.c b/lib/route-table.c index 63a09f2..cde9ee4 100644 --- a/lib/route-table.c +++ b/lib/route-table.c @@ -62,6 +62,7 @@ struct name_node { uint32_t ifi_index; /* Kernel interface index. */ char ifname[IFNAMSIZ]; /* Interface name. */ + int mtu; /* Current MTU */ }; static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); @@ -92,6 +93,7 @@ static int name_table_reset(void); static void name_table_change(const struct rtnetlink_link_change *, void *); static void name_map_clear(void); static struct name_node *name_node_lookup(int ifi_index); +static struct name_node *name_node_lookup_by_ip(ovs_be32 ip); /* Populates 'name' with the name of the interface traffic destined for 'ip' * is likely to egress out of (see route_table_get_ifindex). @@ -100,23 +102,30 @@ static struct name_node *name_node_lookup(int ifi_index); bool route_table_get_name(ovs_be32 ip, char name[IFNAMSIZ]) { - int ifindex; + struct name_node *nn = name_node_lookup_by_ip(ip); - if (!name_table_valid) { - name_table_reset(); + if (!nn) { + ovs_strlcpy(name, nn->ifname, IFNAMSIZ); + return true; } - if (route_table_get_ifindex(ip, &ifindex)) { - struct name_node *nn; + return false; +} - nn = name_node_lookup(ifindex); - if (nn) { - ovs_strlcpy(name, nn->ifname, IFNAMSIZ); - return true; - } +/* Returns the MTU of the interface traffic destined for 'ip' + * is likely to egress out of (see route_table_get_ifindex). + * + * Returns a the MTU if successful, otherwise 0. */ +int +route_table_get_mtu(ovs_be32 ip) +{ + struct name_node *nn = name_node_lookup_by_ip(ip); + + if (nn && nn->mtu > 0) { + return nn->mtu; } - return false; + return 0; } /* Populates 'ifindex' with the interface index traffic destined for 'ip' is @@ -450,6 +459,7 @@ name_table_reset(void) nn = xzalloc(sizeof *nn); nn->ifi_index = change.ifi_index; + nn->mtu = change.mtu; ovs_strlcpy(nn->ifname, change.ifname, IFNAMSIZ); hmap_insert(&name_map, &nn->node, hash_int(nn->ifi_index, 0)); } @@ -482,6 +492,27 @@ name_node_lookup(int ifi_index) return NULL; } +static struct name_node * +name_node_lookup_by_ip(ovs_be32 ip) +{ + int ifindex; + + if (!name_table_valid) { + name_table_reset(); + } + + if (route_table_get_ifindex(ip, &ifindex)) { + struct name_node *nn; + + nn = name_node_lookup(ifindex); + if (nn) { + return nn; + } + } + + return NULL; +} + static void name_map_clear(void) { diff --git a/lib/route-table.h b/lib/route-table.h index 1479249..264c199 100644 --- a/lib/route-table.h +++ b/lib/route-table.h @@ -25,6 +25,7 @@ bool route_table_get_ifindex(ovs_be32 ip, int *ifindex); bool route_table_get_name(ovs_be32 ip, char name[IFNAMSIZ]); +int route_table_get_mtu(ovs_be32 ip); void route_table_register(void); void route_table_unregister(void); void route_table_run(void); -- 1.7.10.2.484.gcd07cc5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev