Skip to content

Commit 5e2b61f

Browse files
committed
ipv4: Remove flowi from struct rtable.
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 <[email protected]>
1 parent 1018b5c commit 5e2b61f

File tree

7 files changed

+146
-94
lines changed

7 files changed

+146
-94
lines changed

include/net/route.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,20 @@ struct fib_info;
5353
struct rtable {
5454
struct dst_entry dst;
5555

56-
/* Cache lookup keys */
57-
struct flowi fl;
56+
/* Lookup key. */
57+
__be32 rt_key_dst;
58+
__be32 rt_key_src;
5859

5960
int rt_genid;
6061
unsigned rt_flags;
6162
__u16 rt_type;
63+
__u8 rt_tos;
6264

6365
__be32 rt_dst; /* Path destination */
6466
__be32 rt_src; /* Path source */
6567
int rt_iif;
68+
int rt_oif;
69+
__u32 rt_mark;
6670

6771
/* Info on neighbour */
6872
__be32 rt_gateway;
@@ -76,12 +80,12 @@ struct rtable {
7680

7781
static inline bool rt_is_input_route(struct rtable *rt)
7882
{
79-
return rt->fl.iif != 0;
83+
return rt->rt_iif != 0;
8084
}
8185

8286
static inline bool rt_is_output_route(struct rtable *rt)
8387
{
84-
return rt->fl.iif == 0;
88+
return rt->rt_iif == 0;
8589
}
8690

8791
struct ip_rt_acct {
@@ -212,11 +216,11 @@ static inline struct rtable *ip_route_newports(struct rtable *rt,
212216
__be16 dport, struct sock *sk)
213217
{
214218
if (sport != orig_sport || dport != orig_dport) {
215-
struct flowi fl = { .oif = rt->fl.oif,
216-
.mark = rt->fl.mark,
217-
.fl4_dst = rt->fl.fl4_dst,
218-
.fl4_src = rt->fl.fl4_src,
219-
.fl4_tos = rt->fl.fl4_tos,
219+
struct flowi fl = { .oif = rt->rt_oif,
220+
.mark = rt->rt_mark,
221+
.fl4_dst = rt->rt_key_dst,
222+
.fl4_src = rt->rt_key_src,
223+
.fl4_tos = rt->rt_tos,
220224
.proto = protocol,
221225
.fl_ip_sport = sport,
222226
.fl_ip_dport = dport };

net/ipv4/icmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
563563
rcu_read_lock();
564564
if (rt_is_input_route(rt) &&
565565
net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr)
566-
dev = dev_get_by_index_rcu(net, rt->fl.iif);
566+
dev = dev_get_by_index_rcu(net, rt->rt_iif);
567567

568568
if (dev)
569569
saddr = inet_select_addr(dev, 0, RT_SCOPE_LINK);

net/ipv4/ipmr.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,12 +1813,22 @@ int ip_mr_input(struct sk_buff *skb)
18131813
if (IPCB(skb)->flags & IPSKB_FORWARDED)
18141814
goto dont_forward;
18151815

1816-
err = ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt);
1817-
if (err < 0) {
1818-
kfree_skb(skb);
1819-
return err;
1816+
{
1817+
struct rtable *rt = skb_rtable(skb);
1818+
struct flowi fl = {
1819+
.fl4_dst = rt->rt_key_dst,
1820+
.fl4_src = rt->rt_key_src,
1821+
.fl4_tos = rt->rt_tos,
1822+
.oif = rt->rt_oif,
1823+
.iif = rt->rt_iif,
1824+
.mark = rt->rt_mark,
1825+
};
1826+
err = ipmr_fib_lookup(net, &fl, &mrt);
1827+
if (err < 0) {
1828+
kfree_skb(skb);
1829+
return err;
1830+
}
18201831
}
1821-
18221832
if (!local) {
18231833
if (IPCB(skb)->opt.router_alert) {
18241834
if (ip_call_ra_chain(skb))
@@ -1946,9 +1956,19 @@ int pim_rcv_v1(struct sk_buff *skb)
19461956

19471957
pim = igmp_hdr(skb);
19481958

1949-
if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0)
1950-
goto drop;
1951-
1959+
{
1960+
struct rtable *rt = skb_rtable(skb);
1961+
struct flowi fl = {
1962+
.fl4_dst = rt->rt_key_dst,
1963+
.fl4_src = rt->rt_key_src,
1964+
.fl4_tos = rt->rt_tos,
1965+
.oif = rt->rt_oif,
1966+
.iif = rt->rt_iif,
1967+
.mark = rt->rt_mark,
1968+
};
1969+
if (ipmr_fib_lookup(net, &fl, &mrt) < 0)
1970+
goto drop;
1971+
}
19521972
if (!mrt->mroute_do_pim ||
19531973
pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
19541974
goto drop;
@@ -1978,9 +1998,19 @@ static int pim_rcv(struct sk_buff *skb)
19781998
csum_fold(skb_checksum(skb, 0, skb->len, 0))))
19791999
goto drop;
19802000

1981-
if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0)
1982-
goto drop;
1983-
2001+
{
2002+
struct rtable *rt = skb_rtable(skb);
2003+
struct flowi fl = {
2004+
.fl4_dst = rt->rt_key_dst,
2005+
.fl4_src = rt->rt_key_src,
2006+
.fl4_tos = rt->rt_tos,
2007+
.oif = rt->rt_oif,
2008+
.iif = rt->rt_iif,
2009+
.mark = rt->rt_mark,
2010+
};
2011+
if (ipmr_fib_lookup(net, &fl, &mrt) < 0)
2012+
goto drop;
2013+
}
19842014
if (__pim_rcv(mrt, skb, sizeof(*pim))) {
19852015
drop:
19862016
kfree_skb(skb);

0 commit comments

Comments
 (0)