ipv4: Make Netfilter's ip_route_me_harder() non-local address compatible
Netfilter's ip_route_me_harder() tries to re-route packets either generated or re-routed by Netfilter. This patch changes ip_route_me_harder() to handle packets from non-locally-bound sockets with IP_TRANSPARENT set as local and to set the appropriate flowi flags when re-doing the routing lookup. Signed-off-by: KOVACS Krisztian <hidden@sch.bme.hu> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
88ef4a5a78
commit
86b08d867d
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <net/inet_sock.h>
|
#include <net/inet_sock.h>
|
||||||
#include <net/snmp.h>
|
#include <net/snmp.h>
|
||||||
|
#include <net/flow.h>
|
||||||
|
|
||||||
struct sock;
|
struct sock;
|
||||||
|
|
||||||
@@ -149,6 +150,11 @@ struct ip_reply_arg {
|
|||||||
|
|
||||||
#define IP_REPLY_ARG_NOSRCCHECK 1
|
#define IP_REPLY_ARG_NOSRCCHECK 1
|
||||||
|
|
||||||
|
static inline __u8 ip_reply_arg_flowi_flags(const struct ip_reply_arg *arg)
|
||||||
|
{
|
||||||
|
return (arg->flags & IP_REPLY_ARG_NOSRCCHECK) ? FLOWI_FLAG_ANYSRC : 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *arg,
|
void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *arg,
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
|
|
||||||
|
@@ -335,6 +335,7 @@ struct dst_entry* inet_csk_route_req(struct sock *sk,
|
|||||||
.saddr = ireq->loc_addr,
|
.saddr = ireq->loc_addr,
|
||||||
.tos = RT_CONN_FLAGS(sk) } },
|
.tos = RT_CONN_FLAGS(sk) } },
|
||||||
.proto = sk->sk_protocol,
|
.proto = sk->sk_protocol,
|
||||||
|
.flags = inet_sk_flowi_flags(sk),
|
||||||
.uli_u = { .ports =
|
.uli_u = { .ports =
|
||||||
{ .sport = inet_sk(sk)->sport,
|
{ .sport = inet_sk(sk)->sport,
|
||||||
.dport = ireq->rmt_port } } };
|
.dport = ireq->rmt_port } } };
|
||||||
|
@@ -340,6 +340,7 @@ int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
|
|||||||
.saddr = inet->saddr,
|
.saddr = inet->saddr,
|
||||||
.tos = RT_CONN_FLAGS(sk) } },
|
.tos = RT_CONN_FLAGS(sk) } },
|
||||||
.proto = sk->sk_protocol,
|
.proto = sk->sk_protocol,
|
||||||
|
.flags = inet_sk_flowi_flags(sk),
|
||||||
.uli_u = { .ports =
|
.uli_u = { .ports =
|
||||||
{ .sport = inet->sport,
|
{ .sport = inet->sport,
|
||||||
.dport = inet->dport } } };
|
.dport = inet->dport } } };
|
||||||
@@ -1371,7 +1372,8 @@ void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *ar
|
|||||||
.uli_u = { .ports =
|
.uli_u = { .ports =
|
||||||
{ .sport = tcp_hdr(skb)->dest,
|
{ .sport = tcp_hdr(skb)->dest,
|
||||||
.dport = tcp_hdr(skb)->source } },
|
.dport = tcp_hdr(skb)->source } },
|
||||||
.proto = sk->sk_protocol };
|
.proto = sk->sk_protocol,
|
||||||
|
.flags = ip_reply_arg_flowi_flags(arg) };
|
||||||
security_skb_classify_flow(skb, &fl);
|
security_skb_classify_flow(skb, &fl);
|
||||||
if (ip_route_output_key(sock_net(sk), &rt, &fl))
|
if (ip_route_output_key(sock_net(sk), &rt, &fl))
|
||||||
return;
|
return;
|
||||||
|
@@ -20,6 +20,8 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type)
|
|||||||
unsigned int type;
|
unsigned int type;
|
||||||
|
|
||||||
type = inet_addr_type(&init_net, iph->saddr);
|
type = inet_addr_type(&init_net, iph->saddr);
|
||||||
|
if (skb->sk && inet_sk(skb->sk)->transparent)
|
||||||
|
type = RTN_LOCAL;
|
||||||
if (addr_type == RTN_UNSPEC)
|
if (addr_type == RTN_UNSPEC)
|
||||||
addr_type = type;
|
addr_type = type;
|
||||||
|
|
||||||
@@ -33,6 +35,7 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type)
|
|||||||
fl.nl_u.ip4_u.tos = RT_TOS(iph->tos);
|
fl.nl_u.ip4_u.tos = RT_TOS(iph->tos);
|
||||||
fl.oif = skb->sk ? skb->sk->sk_bound_dev_if : 0;
|
fl.oif = skb->sk ? skb->sk->sk_bound_dev_if : 0;
|
||||||
fl.mark = skb->mark;
|
fl.mark = skb->mark;
|
||||||
|
fl.flags = skb->sk ? inet_sk_flowi_flags(skb->sk) : 0;
|
||||||
if (ip_route_output_key(&init_net, &rt, &fl) != 0)
|
if (ip_route_output_key(&init_net, &rt, &fl) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#include <linux/cryptohash.h>
|
#include <linux/cryptohash.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <net/tcp.h>
|
#include <net/tcp.h>
|
||||||
|
#include <net/route.h>
|
||||||
|
|
||||||
/* Timestamps: lowest 9 bits store TCP options */
|
/* Timestamps: lowest 9 bits store TCP options */
|
||||||
#define TSBITS 9
|
#define TSBITS 9
|
||||||
@@ -337,6 +338,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
|
|||||||
.saddr = ireq->loc_addr,
|
.saddr = ireq->loc_addr,
|
||||||
.tos = RT_CONN_FLAGS(sk) } },
|
.tos = RT_CONN_FLAGS(sk) } },
|
||||||
.proto = IPPROTO_TCP,
|
.proto = IPPROTO_TCP,
|
||||||
|
.flags = inet_sk_flowi_flags(sk),
|
||||||
.uli_u = { .ports =
|
.uli_u = { .ports =
|
||||||
{ .sport = th->dest,
|
{ .sport = th->dest,
|
||||||
.dport = th->source } } };
|
.dport = th->source } } };
|
||||||
|
Reference in New Issue
Block a user