diff mbox

Use sk_mark for routing lookup in more places

Message ID 200910011814.47689.atis@mikrotik.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Atis Elsts Oct. 1, 2009, 3:14 p.m. UTC
This patch against v2.6.31 adds support for route lookup using sk_mark in some 
more places. The benefits from this patch are the following.
First, SO_MARK option now has effect on UDP sockets too.
Second, ip_queue_xmit() and inet_sk_rebuild_header() could fail to do routing 
lookup correctly if TCP sockets with SO_MARK were used.

Signed-off-by: Atis Elsts <atis@mikrotik.com>
---
 net/ipv4/af_inet.c   |    1 +
 net/ipv4/ip_output.c |    1 +
 net/ipv4/udp.c       |    1 +
 3 files changed, 3 insertions(+)

                                                .saddr = saddr,
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Eric Dumazet Oct. 1, 2009, 4:30 p.m. UTC | #1
Atis Elsts a écrit :
> This patch against v2.6.31 adds support for route lookup using sk_mark in some 
> more places. The benefits from this patch are the following.
> First, SO_MARK option now has effect on UDP sockets too.
> Second, ip_queue_xmit() and inet_sk_rebuild_header() could fail to do routing 
> lookup correctly if TCP sockets with SO_MARK were used.
> 
> Signed-off-by: Atis Elsts <atis@mikrotik.com>

Good catch, thanks !

I used SO_MARK on connected UDP sockets so did not notice the lack
of functionality. (ip_route_connect() does use sk->sk_mark)

Acked-by: Eric Dumazet <eric.dumazet@gmail.com>

> ---
>  net/ipv4/af_inet.c   |    1 +
>  net/ipv4/ip_output.c |    1 +
>  net/ipv4/udp.c       |    1 +
>  3 files changed, 3 insertions(+)
> 
> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> index 566ea6c..7917963 100644
> --- a/net/ipv4/af_inet.c
> +++ b/net/ipv4/af_inet.c
> @@ -1103,6 +1103,7 @@ int inet_sk_rebuild_header(struct sock *sk)
>  {
>         struct flowi fl = {
>                 .oif = sk->sk_bound_dev_if,
> +               .mark = sk->sk_mark,
>                 .nl_u = {
>                         .ip4_u = {
>                                 .daddr  = daddr,
> diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
> index 7ffcd96..e088a97 100644
> --- a/net/ipv4/ip_output.c
> +++ b/net/ipv4/ip_output.c
> @@ -335,6 +335,7 @@ int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
> 
>                 {
>                         struct flowi fl = { .oif = sk->sk_bound_dev_if,
> +                                           .mark = sk->sk_mark,
>                                             .nl_u = { .ip4_u =
>                                                       { .daddr = daddr,
>                                                         .saddr = inet->saddr,
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index 80e3812..f90cdcc 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -688,6 +688,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, 
> struct msghdr *msg,
> 
>         if (rt == NULL) {
>                 struct flowi fl = { .oif = ipc.oif,
> +                                   .mark = sk->sk_mark,
>                                     .nl_u = { .ip4_u =
>                                               { .daddr = faddr,
>                                                 .saddr = saddr,
> --

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Oct. 1, 2009, 10:18 p.m. UTC | #2
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 01 Oct 2009 18:30:06 +0200

> Atis Elsts a écrit :
>> This patch against v2.6.31 adds support for route lookup using sk_mark in some 
>> more places. The benefits from this patch are the following.
>> First, SO_MARK option now has effect on UDP sockets too.
>> Second, ip_queue_xmit() and inet_sk_rebuild_header() could fail to do routing 
>> lookup correctly if TCP sockets with SO_MARK were used.
>> 
>> Signed-off-by: Atis Elsts <atis@mikrotik.com>
> 
> Good catch, thanks !
> 
> I used SO_MARK on connected UDP sockets so did not notice the lack
> of functionality. (ip_route_connect() does use sk->sk_mark)
> 
> Acked-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied, thanks.

But Atis, your patch was whitespace corrupted by your email
client so I had to apply your patch by hand.  Please correct
this problem before submitting future patches, thank you.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 566ea6c..7917963 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1103,6 +1103,7 @@  int inet_sk_rebuild_header(struct sock *sk)
 {
        struct flowi fl = {
                .oif = sk->sk_bound_dev_if,
+               .mark = sk->sk_mark,
                .nl_u = {
                        .ip4_u = {
                                .daddr  = daddr,
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 7ffcd96..e088a97 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -335,6 +335,7 @@  int ip_queue_xmit(struct sk_buff *skb, int ipfragok)

                {
                        struct flowi fl = { .oif = sk->sk_bound_dev_if,
+                                           .mark = sk->sk_mark,
                                            .nl_u = { .ip4_u =
                                                      { .daddr = daddr,
                                                        .saddr = inet->saddr,
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 80e3812..f90cdcc 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -688,6 +688,7 @@  int udp_sendmsg(struct kiocb *iocb, struct sock *sk, 
struct msghdr *msg,

        if (rt == NULL) {
                struct flowi fl = { .oif = ipc.oif,
+                                   .mark = sk->sk_mark,
                                    .nl_u = { .ip4_u =
                                              { .daddr = faddr,