Skip to content

Commit c53ac41

Browse files
Florian Westphalklassert
authored andcommitted
xfrm: remove decode_session indirection from afinfo_policy
No external dependencies, might as well handle this directly. xfrm_afinfo_policy is now 40 bytes on x86_64. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 2e8b4aa commit c53ac41

File tree

4 files changed

+222
-232
lines changed

4 files changed

+222
-232
lines changed

include/net/xfrm.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,6 @@ struct xfrm_policy_afinfo {
326326
xfrm_address_t *saddr,
327327
xfrm_address_t *daddr,
328328
u32 mark);
329-
void (*decode_session)(struct sk_buff *skb,
330-
struct flowi *fl,
331-
int reverse);
332329
int (*fill_dst)(struct xfrm_dst *xdst,
333330
struct net_device *dev,
334331
const struct flowi *fl);

net/ipv4/xfrm4_policy.c

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/err.h>
1313
#include <linux/kernel.h>
1414
#include <linux/inetdevice.h>
15-
#include <linux/if_tunnel.h>
1615
#include <net/dst.h>
1716
#include <net/xfrm.h>
1817
#include <net/ip.h>
@@ -96,118 +95,6 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
9695
return 0;
9796
}
9897

99-
static void
100-
_decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
101-
{
102-
const struct iphdr *iph = ip_hdr(skb);
103-
u8 *xprth = skb_network_header(skb) + iph->ihl * 4;
104-
struct flowi4 *fl4 = &fl->u.ip4;
105-
int oif = 0;
106-
107-
if (skb_dst(skb))
108-
oif = skb_dst(skb)->dev->ifindex;
109-
110-
memset(fl4, 0, sizeof(struct flowi4));
111-
fl4->flowi4_mark = skb->mark;
112-
fl4->flowi4_oif = reverse ? skb->skb_iif : oif;
113-
114-
if (!ip_is_fragment(iph)) {
115-
switch (iph->protocol) {
116-
case IPPROTO_UDP:
117-
case IPPROTO_UDPLITE:
118-
case IPPROTO_TCP:
119-
case IPPROTO_SCTP:
120-
case IPPROTO_DCCP:
121-
if (xprth + 4 < skb->data ||
122-
pskb_may_pull(skb, xprth + 4 - skb->data)) {
123-
__be16 *ports;
124-
125-
xprth = skb_network_header(skb) + iph->ihl * 4;
126-
ports = (__be16 *)xprth;
127-
128-
fl4->fl4_sport = ports[!!reverse];
129-
fl4->fl4_dport = ports[!reverse];
130-
}
131-
break;
132-
133-
case IPPROTO_ICMP:
134-
if (xprth + 2 < skb->data ||
135-
pskb_may_pull(skb, xprth + 2 - skb->data)) {
136-
u8 *icmp;
137-
138-
xprth = skb_network_header(skb) + iph->ihl * 4;
139-
icmp = xprth;
140-
141-
fl4->fl4_icmp_type = icmp[0];
142-
fl4->fl4_icmp_code = icmp[1];
143-
}
144-
break;
145-
146-
case IPPROTO_ESP:
147-
if (xprth + 4 < skb->data ||
148-
pskb_may_pull(skb, xprth + 4 - skb->data)) {
149-
__be32 *ehdr;
150-
151-
xprth = skb_network_header(skb) + iph->ihl * 4;
152-
ehdr = (__be32 *)xprth;
153-
154-
fl4->fl4_ipsec_spi = ehdr[0];
155-
}
156-
break;
157-
158-
case IPPROTO_AH:
159-
if (xprth + 8 < skb->data ||
160-
pskb_may_pull(skb, xprth + 8 - skb->data)) {
161-
__be32 *ah_hdr;
162-
163-
xprth = skb_network_header(skb) + iph->ihl * 4;
164-
ah_hdr = (__be32 *)xprth;
165-
166-
fl4->fl4_ipsec_spi = ah_hdr[1];
167-
}
168-
break;
169-
170-
case IPPROTO_COMP:
171-
if (xprth + 4 < skb->data ||
172-
pskb_may_pull(skb, xprth + 4 - skb->data)) {
173-
__be16 *ipcomp_hdr;
174-
175-
xprth = skb_network_header(skb) + iph->ihl * 4;
176-
ipcomp_hdr = (__be16 *)xprth;
177-
178-
fl4->fl4_ipsec_spi = htonl(ntohs(ipcomp_hdr[1]));
179-
}
180-
break;
181-
182-
case IPPROTO_GRE:
183-
if (xprth + 12 < skb->data ||
184-
pskb_may_pull(skb, xprth + 12 - skb->data)) {
185-
__be16 *greflags;
186-
__be32 *gre_hdr;
187-
188-
xprth = skb_network_header(skb) + iph->ihl * 4;
189-
greflags = (__be16 *)xprth;
190-
gre_hdr = (__be32 *)xprth;
191-
192-
if (greflags[0] & GRE_KEY) {
193-
if (greflags[0] & GRE_CSUM)
194-
gre_hdr++;
195-
fl4->fl4_gre_key = gre_hdr[1];
196-
}
197-
}
198-
break;
199-
200-
default:
201-
fl4->fl4_ipsec_spi = 0;
202-
break;
203-
}
204-
}
205-
fl4->flowi4_proto = iph->protocol;
206-
fl4->daddr = reverse ? iph->saddr : iph->daddr;
207-
fl4->saddr = reverse ? iph->daddr : iph->saddr;
208-
fl4->flowi4_tos = iph->tos;
209-
}
210-
21198
static void xfrm4_update_pmtu(struct dst_entry *dst, struct sock *sk,
21299
struct sk_buff *skb, u32 mtu)
213100
{
@@ -260,7 +147,6 @@ static const struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
260147
.dst_ops = &xfrm4_dst_ops_template,
261148
.dst_lookup = xfrm4_dst_lookup,
262149
.get_saddr = xfrm4_get_saddr,
263-
.decode_session = _decode_session4,
264150
.fill_dst = xfrm4_fill_dst,
265151
.blackhole_route = ipv4_blackhole_route,
266152
};

net/ipv6/xfrm6_policy.c

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#include <net/ipv6.h>
2323
#include <net/ip6_route.h>
2424
#include <net/l3mdev.h>
25-
#if IS_ENABLED(CONFIG_IPV6_MIP6)
26-
#include <net/mip6.h>
27-
#endif
2825

2926
static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif,
3027
const xfrm_address_t *saddr,
@@ -100,108 +97,6 @@ static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
10097
return 0;
10198
}
10299

103-
static inline void
104-
_decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
105-
{
106-
struct flowi6 *fl6 = &fl->u.ip6;
107-
int onlyproto = 0;
108-
const struct ipv6hdr *hdr = ipv6_hdr(skb);
109-
u32 offset = sizeof(*hdr);
110-
struct ipv6_opt_hdr *exthdr;
111-
const unsigned char *nh = skb_network_header(skb);
112-
u16 nhoff = IP6CB(skb)->nhoff;
113-
int oif = 0;
114-
u8 nexthdr;
115-
116-
if (!nhoff)
117-
nhoff = offsetof(struct ipv6hdr, nexthdr);
118-
119-
nexthdr = nh[nhoff];
120-
121-
if (skb_dst(skb))
122-
oif = skb_dst(skb)->dev->ifindex;
123-
124-
memset(fl6, 0, sizeof(struct flowi6));
125-
fl6->flowi6_mark = skb->mark;
126-
fl6->flowi6_oif = reverse ? skb->skb_iif : oif;
127-
128-
fl6->daddr = reverse ? hdr->saddr : hdr->daddr;
129-
fl6->saddr = reverse ? hdr->daddr : hdr->saddr;
130-
131-
while (nh + offset + sizeof(*exthdr) < skb->data ||
132-
pskb_may_pull(skb, nh + offset + sizeof(*exthdr) - skb->data)) {
133-
nh = skb_network_header(skb);
134-
exthdr = (struct ipv6_opt_hdr *)(nh + offset);
135-
136-
switch (nexthdr) {
137-
case NEXTHDR_FRAGMENT:
138-
onlyproto = 1;
139-
/* fall through */
140-
case NEXTHDR_ROUTING:
141-
case NEXTHDR_HOP:
142-
case NEXTHDR_DEST:
143-
offset += ipv6_optlen(exthdr);
144-
nexthdr = exthdr->nexthdr;
145-
exthdr = (struct ipv6_opt_hdr *)(nh + offset);
146-
break;
147-
148-
case IPPROTO_UDP:
149-
case IPPROTO_UDPLITE:
150-
case IPPROTO_TCP:
151-
case IPPROTO_SCTP:
152-
case IPPROTO_DCCP:
153-
if (!onlyproto && (nh + offset + 4 < skb->data ||
154-
pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
155-
__be16 *ports;
156-
157-
nh = skb_network_header(skb);
158-
ports = (__be16 *)(nh + offset);
159-
fl6->fl6_sport = ports[!!reverse];
160-
fl6->fl6_dport = ports[!reverse];
161-
}
162-
fl6->flowi6_proto = nexthdr;
163-
return;
164-
165-
case IPPROTO_ICMPV6:
166-
if (!onlyproto && (nh + offset + 2 < skb->data ||
167-
pskb_may_pull(skb, nh + offset + 2 - skb->data))) {
168-
u8 *icmp;
169-
170-
nh = skb_network_header(skb);
171-
icmp = (u8 *)(nh + offset);
172-
fl6->fl6_icmp_type = icmp[0];
173-
fl6->fl6_icmp_code = icmp[1];
174-
}
175-
fl6->flowi6_proto = nexthdr;
176-
return;
177-
178-
#if IS_ENABLED(CONFIG_IPV6_MIP6)
179-
case IPPROTO_MH:
180-
offset += ipv6_optlen(exthdr);
181-
if (!onlyproto && (nh + offset + 3 < skb->data ||
182-
pskb_may_pull(skb, nh + offset + 3 - skb->data))) {
183-
struct ip6_mh *mh;
184-
185-
nh = skb_network_header(skb);
186-
mh = (struct ip6_mh *)(nh + offset);
187-
fl6->fl6_mh_type = mh->ip6mh_type;
188-
}
189-
fl6->flowi6_proto = nexthdr;
190-
return;
191-
#endif
192-
193-
/* XXX Why are there these headers? */
194-
case IPPROTO_AH:
195-
case IPPROTO_ESP:
196-
case IPPROTO_COMP:
197-
default:
198-
fl6->fl6_ipsec_spi = 0;
199-
fl6->flowi6_proto = nexthdr;
200-
return;
201-
}
202-
}
203-
}
204-
205100
static void xfrm6_update_pmtu(struct dst_entry *dst, struct sock *sk,
206101
struct sk_buff *skb, u32 mtu)
207102
{
@@ -273,7 +168,6 @@ static const struct xfrm_policy_afinfo xfrm6_policy_afinfo = {
273168
.dst_ops = &xfrm6_dst_ops_template,
274169
.dst_lookup = xfrm6_dst_lookup,
275170
.get_saddr = xfrm6_get_saddr,
276-
.decode_session = _decode_session6,
277171
.fill_dst = xfrm6_fill_dst,
278172
.blackhole_route = ip6_blackhole_route,
279173
};

0 commit comments

Comments
 (0)