2005-04-16 22:20:36 +00:00
|
|
|
/* IPv4-specific defines for netfilter.
|
|
|
|
* (C)1998 Rusty Russell -- This code is GPL.
|
|
|
|
*/
|
2012-10-13 09:46:48 +00:00
|
|
|
#ifndef __LINUX_IP_NETFILTER_H
|
|
|
|
#define __LINUX_IP_NETFILTER_H
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-10-13 09:46:48 +00:00
|
|
|
#include <uapi/linux/netfilter_ipv4.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-12-20 15:12:55 +00:00
|
|
|
/* Extra routing may needed on local out, as the QUEUE target never returns
|
|
|
|
* control to the table.
|
|
|
|
*/
|
|
|
|
struct ip_rt_info {
|
|
|
|
__be32 daddr;
|
|
|
|
__be32 saddr;
|
|
|
|
u_int8_t tos;
|
|
|
|
u_int32_t mark;
|
|
|
|
};
|
|
|
|
|
netfilter: use actual socket sk rather than skb sk when routing harder
If netfilter changes the packet mark when mangling, the packet is
rerouted using the route_me_harder set of functions. Prior to this
commit, there's one big difference between route_me_harder and the
ordinary initial routing functions, described in the comment above
__ip_queue_xmit():
/* Note: skb->sk can be different from sk, in case of tunnels */
int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
That function goes on to correctly make use of sk->sk_bound_dev_if,
rather than skb->sk->sk_bound_dev_if. And indeed the comment is true: a
tunnel will receive a packet in ndo_start_xmit with an initial skb->sk.
It will make some transformations to that packet, and then it will send
the encapsulated packet out of a *new* socket. That new socket will
basically always have a different sk_bound_dev_if (otherwise there'd be
a routing loop). So for the purposes of routing the encapsulated packet,
the routing information as it pertains to the socket should come from
that socket's sk, rather than the packet's original skb->sk. For that
reason __ip_queue_xmit() and related functions all do the right thing.
One might argue that all tunnels should just call skb_orphan(skb) before
transmitting the encapsulated packet into the new socket. But tunnels do
*not* do this -- and this is wisely avoided in skb_scrub_packet() too --
because features like TSQ rely on skb->destructor() being called when
that buffer space is truely available again. Calling skb_orphan(skb) too
early would result in buffers filling up unnecessarily and accounting
info being all wrong. Instead, additional routing must take into account
the new sk, just as __ip_queue_xmit() notes.
So, this commit addresses the problem by fishing the correct sk out of
state->sk -- it's already set properly in the call to nf_hook() in
__ip_local_out(), which receives the sk as part of its normal
functionality. So we make sure to plumb state->sk through the various
route_me_harder functions, and then make correct use of it following the
example of __ip_queue_xmit().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-10-29 02:56:06 +00:00
|
|
|
int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, unsigned addr_type);
|
2017-11-27 20:55:14 +00:00
|
|
|
|
2017-11-27 21:50:26 +00:00
|
|
|
struct nf_queue_entry;
|
|
|
|
|
2017-11-27 20:55:14 +00:00
|
|
|
#ifdef CONFIG_INET
|
2013-09-26 21:48:15 +00:00
|
|
|
__sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
|
|
|
|
unsigned int dataoff, u_int8_t protocol);
|
2017-11-27 21:29:52 +00:00
|
|
|
int nf_ip_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
|
|
|
|
bool strict);
|
2017-11-27 20:55:14 +00:00
|
|
|
#else
|
|
|
|
static inline __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
|
|
|
|
unsigned int dataoff, u_int8_t protocol)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-11-27 21:29:52 +00:00
|
|
|
static inline int nf_ip_route(struct net *net, struct dst_entry **dst,
|
|
|
|
struct flowi *fl, bool strict)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2017-11-27 20:55:14 +00:00
|
|
|
#endif /* CONFIG_INET */
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /*__LINUX_IP_NETFILTER_H*/
|