diff options
| author | Michel Machado <michel@digirati.com.br> | 2012-06-12 06:16:35 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2012-06-12 21:51:09 -0400 |
| commit | 95603e2293de556de7e82221649bfd7fd98b64a3 (patch) | |
| tree | d90e7570b072f62ee4fefa619b93ec771bfd9f95 /net | |
| parent | de063b7040dcd9fbc9a1847fa44f0af13e19d6de (diff) | |
net-next: add dev_loopback_xmit() to avoid duplicate code
Add dev_loopback_xmit() in order to deduplicate functions
ip_dev_loopback_xmit() (in net/ipv4/ip_output.c) and
ip6_dev_loopback_xmit() (in net/ipv6/ip6_output.c).
I was about to reinvent the wheel when I noticed that
ip_dev_loopback_xmit() and ip6_dev_loopback_xmit() do exactly what I
need and are not IP-only functions, but they were not available to reuse
elsewhere.
ip6_dev_loopback_xmit() does not have line "skb_dst_force(skb);", but I
understand that this is harmless, and should be in dev_loopback_xmit().
Signed-off-by: Michel Machado <michel@digirati.com.br>
CC: "David S. Miller" <davem@davemloft.net>
CC: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
CC: James Morris <jmorris@namei.org>
CC: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
CC: Patrick McHardy <kaber@trash.net>
CC: Eric Dumazet <edumazet@google.com>
CC: Jiri Pirko <jpirko@redhat.com>
CC: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
CC: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
| -rw-r--r-- | net/core/dev.c | 17 | ||||
| -rw-r--r-- | net/ipv4/ip_output.c | 17 | ||||
| -rw-r--r-- | net/ipv6/ip6_output.c | 15 |
3 files changed, 20 insertions, 29 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index cd0981977f5c..c6e29ea65bd9 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
| @@ -2476,6 +2476,23 @@ static DEFINE_PER_CPU(int, xmit_recursion); | |||
| 2476 | #define RECURSION_LIMIT 10 | 2476 | #define RECURSION_LIMIT 10 |
| 2477 | 2477 | ||
| 2478 | /** | 2478 | /** |
| 2479 | * dev_loopback_xmit - loop back @skb | ||
| 2480 | * @skb: buffer to transmit | ||
| 2481 | */ | ||
| 2482 | int dev_loopback_xmit(struct sk_buff *skb) | ||
| 2483 | { | ||
| 2484 | skb_reset_mac_header(skb); | ||
| 2485 | __skb_pull(skb, skb_network_offset(skb)); | ||
| 2486 | skb->pkt_type = PACKET_LOOPBACK; | ||
| 2487 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
| 2488 | WARN_ON(!skb_dst(skb)); | ||
| 2489 | skb_dst_force(skb); | ||
| 2490 | netif_rx_ni(skb); | ||
| 2491 | return 0; | ||
| 2492 | } | ||
| 2493 | EXPORT_SYMBOL(dev_loopback_xmit); | ||
| 2494 | |||
| 2495 | /** | ||
| 2479 | * dev_queue_xmit - transmit a buffer | 2496 | * dev_queue_xmit - transmit a buffer |
| 2480 | * @skb: buffer to transmit | 2497 | * @skb: buffer to transmit |
| 2481 | * | 2498 | * |
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index b99ca4e154b9..0f3185a662c3 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c | |||
| @@ -113,19 +113,6 @@ int ip_local_out(struct sk_buff *skb) | |||
| 113 | } | 113 | } |
| 114 | EXPORT_SYMBOL_GPL(ip_local_out); | 114 | EXPORT_SYMBOL_GPL(ip_local_out); |
| 115 | 115 | ||
| 116 | /* dev_loopback_xmit for use with netfilter. */ | ||
| 117 | static int ip_dev_loopback_xmit(struct sk_buff *newskb) | ||
| 118 | { | ||
| 119 | skb_reset_mac_header(newskb); | ||
| 120 | __skb_pull(newskb, skb_network_offset(newskb)); | ||
| 121 | newskb->pkt_type = PACKET_LOOPBACK; | ||
| 122 | newskb->ip_summed = CHECKSUM_UNNECESSARY; | ||
| 123 | WARN_ON(!skb_dst(newskb)); | ||
| 124 | skb_dst_force(newskb); | ||
| 125 | netif_rx_ni(newskb); | ||
| 126 | return 0; | ||
| 127 | } | ||
| 128 | |||
| 129 | static inline int ip_select_ttl(struct inet_sock *inet, struct dst_entry *dst) | 116 | static inline int ip_select_ttl(struct inet_sock *inet, struct dst_entry *dst) |
| 130 | { | 117 | { |
| 131 | int ttl = inet->uc_ttl; | 118 | int ttl = inet->uc_ttl; |
| @@ -281,7 +268,7 @@ int ip_mc_output(struct sk_buff *skb) | |||
| 281 | if (newskb) | 268 | if (newskb) |
| 282 | NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING, | 269 | NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING, |
| 283 | newskb, NULL, newskb->dev, | 270 | newskb, NULL, newskb->dev, |
| 284 | ip_dev_loopback_xmit); | 271 | dev_loopback_xmit); |
| 285 | } | 272 | } |
| 286 | 273 | ||
| 287 | /* Multicasts with ttl 0 must not go beyond the host */ | 274 | /* Multicasts with ttl 0 must not go beyond the host */ |
| @@ -296,7 +283,7 @@ int ip_mc_output(struct sk_buff *skb) | |||
| 296 | struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC); | 283 | struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC); |
| 297 | if (newskb) | 284 | if (newskb) |
| 298 | NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING, newskb, | 285 | NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING, newskb, |
| 299 | NULL, newskb->dev, ip_dev_loopback_xmit); | 286 | NULL, newskb->dev, dev_loopback_xmit); |
| 300 | } | 287 | } |
| 301 | 288 | ||
| 302 | return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING, skb, NULL, | 289 | return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING, skb, NULL, |
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 62fcf3e48aca..ee1bb450bfe4 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c | |||
| @@ -83,19 +83,6 @@ int ip6_local_out(struct sk_buff *skb) | |||
| 83 | } | 83 | } |
| 84 | EXPORT_SYMBOL_GPL(ip6_local_out); | 84 | EXPORT_SYMBOL_GPL(ip6_local_out); |
| 85 | 85 | ||
| 86 | /* dev_loopback_xmit for use with netfilter. */ | ||
| 87 | static int ip6_dev_loopback_xmit(struct sk_buff *newskb) | ||
| 88 | { | ||
| 89 | skb_reset_mac_header(newskb); | ||
| 90 | __skb_pull(newskb, skb_network_offset(newskb)); | ||
| 91 | newskb->pkt_type = PACKET_LOOPBACK; | ||
| 92 | newskb->ip_summed = CHECKSUM_UNNECESSARY; | ||
| 93 | WARN_ON(!skb_dst(newskb)); | ||
| 94 | |||
| 95 | netif_rx_ni(newskb); | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | |||
| 99 | static int ip6_finish_output2(struct sk_buff *skb) | 86 | static int ip6_finish_output2(struct sk_buff *skb) |
| 100 | { | 87 | { |
| 101 | struct dst_entry *dst = skb_dst(skb); | 88 | struct dst_entry *dst = skb_dst(skb); |
| @@ -121,7 +108,7 @@ static int ip6_finish_output2(struct sk_buff *skb) | |||
| 121 | if (newskb) | 108 | if (newskb) |
| 122 | NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, | 109 | NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, |
| 123 | newskb, NULL, newskb->dev, | 110 | newskb, NULL, newskb->dev, |
| 124 | ip6_dev_loopback_xmit); | 111 | dev_loopback_xmit); |
| 125 | 112 | ||
| 126 | if (ipv6_hdr(skb)->hop_limit == 0) { | 113 | if (ipv6_hdr(skb)->hop_limit == 0) { |
| 127 | IP6_INC_STATS(dev_net(dev), idev, | 114 | IP6_INC_STATS(dev_net(dev), idev, |
