Skip to content

Commit

Permalink
ipv4: Remove flowi from struct rtable.
Browse files Browse the repository at this point in the history
The only necessary parts are the src/dst addresses, the
interface indexes, the TOS, and the mark.

The rest is unnecessary bloat, which amounts to nearly
50 bytes on 64-bit.

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Mar 5, 2011
1 parent 1018b5c commit 5e2b61f
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 94 deletions.
22 changes: 13 additions & 9 deletions include/net/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@ struct fib_info;
struct rtable {
struct dst_entry dst;

/* Cache lookup keys */
struct flowi fl;
/* Lookup key. */
__be32 rt_key_dst;
__be32 rt_key_src;

int rt_genid;
unsigned rt_flags;
__u16 rt_type;
__u8 rt_tos;

__be32 rt_dst; /* Path destination */
__be32 rt_src; /* Path source */
int rt_iif;
int rt_oif;
__u32 rt_mark;

/* Info on neighbour */
__be32 rt_gateway;
Expand All @@ -76,12 +80,12 @@ struct rtable {

static inline bool rt_is_input_route(struct rtable *rt)
{
return rt->fl.iif != 0;
return rt->rt_iif != 0;
}

static inline bool rt_is_output_route(struct rtable *rt)
{
return rt->fl.iif == 0;
return rt->rt_iif == 0;
}

struct ip_rt_acct {
Expand Down Expand Up @@ -212,11 +216,11 @@ static inline struct rtable *ip_route_newports(struct rtable *rt,
__be16 dport, struct sock *sk)
{
if (sport != orig_sport || dport != orig_dport) {
struct flowi fl = { .oif = rt->fl.oif,
.mark = rt->fl.mark,
.fl4_dst = rt->fl.fl4_dst,
.fl4_src = rt->fl.fl4_src,
.fl4_tos = rt->fl.fl4_tos,
struct flowi fl = { .oif = rt->rt_oif,
.mark = rt->rt_mark,
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.proto = protocol,
.fl_ip_sport = sport,
.fl_ip_dport = dport };
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
rcu_read_lock();
if (rt_is_input_route(rt) &&
net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr)
dev = dev_get_by_index_rcu(net, rt->fl.iif);
dev = dev_get_by_index_rcu(net, rt->rt_iif);

if (dev)
saddr = inet_select_addr(dev, 0, RT_SCOPE_LINK);
Expand Down
52 changes: 41 additions & 11 deletions net/ipv4/ipmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1813,12 +1813,22 @@ int ip_mr_input(struct sk_buff *skb)
if (IPCB(skb)->flags & IPSKB_FORWARDED)
goto dont_forward;

err = ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt);
if (err < 0) {
kfree_skb(skb);
return err;
{
struct rtable *rt = skb_rtable(skb);
struct flowi fl = {
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.oif = rt->rt_oif,
.iif = rt->rt_iif,
.mark = rt->rt_mark,
};
err = ipmr_fib_lookup(net, &fl, &mrt);
if (err < 0) {
kfree_skb(skb);
return err;
}
}

if (!local) {
if (IPCB(skb)->opt.router_alert) {
if (ip_call_ra_chain(skb))
Expand Down Expand Up @@ -1946,9 +1956,19 @@ int pim_rcv_v1(struct sk_buff *skb)

pim = igmp_hdr(skb);

if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0)
goto drop;

{
struct rtable *rt = skb_rtable(skb);
struct flowi fl = {
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.oif = rt->rt_oif,
.iif = rt->rt_iif,
.mark = rt->rt_mark,
};
if (ipmr_fib_lookup(net, &fl, &mrt) < 0)
goto drop;
}
if (!mrt->mroute_do_pim ||
pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
goto drop;
Expand Down Expand Up @@ -1978,9 +1998,19 @@ static int pim_rcv(struct sk_buff *skb)
csum_fold(skb_checksum(skb, 0, skb->len, 0))))
goto drop;

if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0)
goto drop;

{
struct rtable *rt = skb_rtable(skb);
struct flowi fl = {
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.oif = rt->rt_oif,
.iif = rt->rt_iif,
.mark = rt->rt_mark,
};
if (ipmr_fib_lookup(net, &fl, &mrt) < 0)
goto drop;
}
if (__pim_rcv(mrt, skb, sizeof(*pim))) {
drop:
kfree_skb(skb);
Expand Down
Loading

0 comments on commit 5e2b61f

Please sign in to comment.