diff options
author | Changli Gao <xiaosuo@gmail.com> | 2010-09-01 23:56:51 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-09-02 13:12:06 -0400 |
commit | deffd77759e3ceb936f0760cc54a213881577a83 (patch) | |
tree | 33bb636f23abde623b4ef2ceb5d4ba89167bcea9 /net/ipv4/arp.c | |
parent | c07b68e841bd737e2ebeb57268d251c89ccc5010 (diff) |
net: arp: code cleanup
Clean the code up according to Documentation/CodingStyle.
Don't initialize the variable dont_send in arp_process().
Remove the temporary varialbe flags in arp_state_to_flags().
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/arp.c')
-rw-r--r-- | net/ipv4/arp.c | 226 |
1 files changed, 123 insertions, 103 deletions
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 96c1955b3e2f..dcfe7e961c10 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c | |||
@@ -55,7 +55,7 @@ | |||
55 | * Stuart Cheshire : Metricom and grat arp fixes | 55 | * Stuart Cheshire : Metricom and grat arp fixes |
56 | * *** FOR 2.1 clean this up *** | 56 | * *** FOR 2.1 clean this up *** |
57 | * Lawrence V. Stefani: (08/12/96) Added FDDI support. | 57 | * Lawrence V. Stefani: (08/12/96) Added FDDI support. |
58 | * Alan Cox : Took the AP1000 nasty FDDI hack and | 58 | * Alan Cox : Took the AP1000 nasty FDDI hack and |
59 | * folded into the mainstream FDDI code. | 59 | * folded into the mainstream FDDI code. |
60 | * Ack spit, Linus how did you allow that | 60 | * Ack spit, Linus how did you allow that |
61 | * one in... | 61 | * one in... |
@@ -120,7 +120,7 @@ EXPORT_SYMBOL(clip_tbl_hook); | |||
120 | #endif | 120 | #endif |
121 | 121 | ||
122 | #include <asm/system.h> | 122 | #include <asm/system.h> |
123 | #include <asm/uaccess.h> | 123 | #include <linux/uaccess.h> |
124 | 124 | ||
125 | #include <linux/netfilter_arp.h> | 125 | #include <linux/netfilter_arp.h> |
126 | 126 | ||
@@ -173,32 +173,32 @@ const struct neigh_ops arp_broken_ops = { | |||
173 | EXPORT_SYMBOL(arp_broken_ops); | 173 | EXPORT_SYMBOL(arp_broken_ops); |
174 | 174 | ||
175 | struct neigh_table arp_tbl = { | 175 | struct neigh_table arp_tbl = { |
176 | .family = AF_INET, | 176 | .family = AF_INET, |
177 | .entry_size = sizeof(struct neighbour) + 4, | 177 | .entry_size = sizeof(struct neighbour) + 4, |
178 | .key_len = 4, | 178 | .key_len = 4, |
179 | .hash = arp_hash, | 179 | .hash = arp_hash, |
180 | .constructor = arp_constructor, | 180 | .constructor = arp_constructor, |
181 | .proxy_redo = parp_redo, | 181 | .proxy_redo = parp_redo, |
182 | .id = "arp_cache", | 182 | .id = "arp_cache", |
183 | .parms = { | 183 | .parms = { |
184 | .tbl = &arp_tbl, | 184 | .tbl = &arp_tbl, |
185 | .base_reachable_time = 30 * HZ, | 185 | .base_reachable_time = 30 * HZ, |
186 | .retrans_time = 1 * HZ, | 186 | .retrans_time = 1 * HZ, |
187 | .gc_staletime = 60 * HZ, | 187 | .gc_staletime = 60 * HZ, |
188 | .reachable_time = 30 * HZ, | 188 | .reachable_time = 30 * HZ, |
189 | .delay_probe_time = 5 * HZ, | 189 | .delay_probe_time = 5 * HZ, |
190 | .queue_len = 3, | 190 | .queue_len = 3, |
191 | .ucast_probes = 3, | 191 | .ucast_probes = 3, |
192 | .mcast_probes = 3, | 192 | .mcast_probes = 3, |
193 | .anycast_delay = 1 * HZ, | 193 | .anycast_delay = 1 * HZ, |
194 | .proxy_delay = (8 * HZ) / 10, | 194 | .proxy_delay = (8 * HZ) / 10, |
195 | .proxy_qlen = 64, | 195 | .proxy_qlen = 64, |
196 | .locktime = 1 * HZ, | 196 | .locktime = 1 * HZ, |
197 | }, | 197 | }, |
198 | .gc_interval = 30 * HZ, | 198 | .gc_interval = 30 * HZ, |
199 | .gc_thresh1 = 128, | 199 | .gc_thresh1 = 128, |
200 | .gc_thresh2 = 512, | 200 | .gc_thresh2 = 512, |
201 | .gc_thresh3 = 1024, | 201 | .gc_thresh3 = 1024, |
202 | }; | 202 | }; |
203 | EXPORT_SYMBOL(arp_tbl); | 203 | EXPORT_SYMBOL(arp_tbl); |
204 | 204 | ||
@@ -233,7 +233,7 @@ static u32 arp_hash(const void *pkey, const struct net_device *dev) | |||
233 | 233 | ||
234 | static int arp_constructor(struct neighbour *neigh) | 234 | static int arp_constructor(struct neighbour *neigh) |
235 | { | 235 | { |
236 | __be32 addr = *(__be32*)neigh->primary_key; | 236 | __be32 addr = *(__be32 *)neigh->primary_key; |
237 | struct net_device *dev = neigh->dev; | 237 | struct net_device *dev = neigh->dev; |
238 | struct in_device *in_dev; | 238 | struct in_device *in_dev; |
239 | struct neigh_parms *parms; | 239 | struct neigh_parms *parms; |
@@ -296,16 +296,19 @@ static int arp_constructor(struct neighbour *neigh) | |||
296 | neigh->ops = &arp_broken_ops; | 296 | neigh->ops = &arp_broken_ops; |
297 | neigh->output = neigh->ops->output; | 297 | neigh->output = neigh->ops->output; |
298 | return 0; | 298 | return 0; |
299 | #else | ||
300 | break; | ||
299 | #endif | 301 | #endif |
300 | ;} | 302 | } |
301 | #endif | 303 | #endif |
302 | if (neigh->type == RTN_MULTICAST) { | 304 | if (neigh->type == RTN_MULTICAST) { |
303 | neigh->nud_state = NUD_NOARP; | 305 | neigh->nud_state = NUD_NOARP; |
304 | arp_mc_map(addr, neigh->ha, dev, 1); | 306 | arp_mc_map(addr, neigh->ha, dev, 1); |
305 | } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { | 307 | } else if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) { |
306 | neigh->nud_state = NUD_NOARP; | 308 | neigh->nud_state = NUD_NOARP; |
307 | memcpy(neigh->ha, dev->dev_addr, dev->addr_len); | 309 | memcpy(neigh->ha, dev->dev_addr, dev->addr_len); |
308 | } else if (neigh->type == RTN_BROADCAST || dev->flags&IFF_POINTOPOINT) { | 310 | } else if (neigh->type == RTN_BROADCAST || |
311 | (dev->flags & IFF_POINTOPOINT)) { | ||
309 | neigh->nud_state = NUD_NOARP; | 312 | neigh->nud_state = NUD_NOARP; |
310 | memcpy(neigh->ha, dev->broadcast, dev->addr_len); | 313 | memcpy(neigh->ha, dev->broadcast, dev->addr_len); |
311 | } | 314 | } |
@@ -315,7 +318,7 @@ static int arp_constructor(struct neighbour *neigh) | |||
315 | else | 318 | else |
316 | neigh->ops = &arp_generic_ops; | 319 | neigh->ops = &arp_generic_ops; |
317 | 320 | ||
318 | if (neigh->nud_state&NUD_VALID) | 321 | if (neigh->nud_state & NUD_VALID) |
319 | neigh->output = neigh->ops->connected_output; | 322 | neigh->output = neigh->ops->connected_output; |
320 | else | 323 | else |
321 | neigh->output = neigh->ops->output; | 324 | neigh->output = neigh->ops->output; |
@@ -334,7 +337,7 @@ static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb) | |||
334 | __be32 saddr = 0; | 337 | __be32 saddr = 0; |
335 | u8 *dst_ha = NULL; | 338 | u8 *dst_ha = NULL; |
336 | struct net_device *dev = neigh->dev; | 339 | struct net_device *dev = neigh->dev; |
337 | __be32 target = *(__be32*)neigh->primary_key; | 340 | __be32 target = *(__be32 *)neigh->primary_key; |
338 | int probes = atomic_read(&neigh->probes); | 341 | int probes = atomic_read(&neigh->probes); |
339 | struct in_device *in_dev; | 342 | struct in_device *in_dev; |
340 | 343 | ||
@@ -347,7 +350,8 @@ static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb) | |||
347 | switch (IN_DEV_ARP_ANNOUNCE(in_dev)) { | 350 | switch (IN_DEV_ARP_ANNOUNCE(in_dev)) { |
348 | default: | 351 | default: |
349 | case 0: /* By default announce any local IP */ | 352 | case 0: /* By default announce any local IP */ |
350 | if (skb && inet_addr_type(dev_net(dev), ip_hdr(skb)->saddr) == RTN_LOCAL) | 353 | if (skb && inet_addr_type(dev_net(dev), |
354 | ip_hdr(skb)->saddr) == RTN_LOCAL) | ||
351 | saddr = ip_hdr(skb)->saddr; | 355 | saddr = ip_hdr(skb)->saddr; |
352 | break; | 356 | break; |
353 | case 1: /* Restrict announcements of saddr in same subnet */ | 357 | case 1: /* Restrict announcements of saddr in same subnet */ |
@@ -369,16 +373,21 @@ static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb) | |||
369 | if (!saddr) | 373 | if (!saddr) |
370 | saddr = inet_select_addr(dev, target, RT_SCOPE_LINK); | 374 | saddr = inet_select_addr(dev, target, RT_SCOPE_LINK); |
371 | 375 | ||
372 | if ((probes -= neigh->parms->ucast_probes) < 0) { | 376 | probes -= neigh->parms->ucast_probes; |
373 | if (!(neigh->nud_state&NUD_VALID)) | 377 | if (probes < 0) { |
374 | printk(KERN_DEBUG "trying to ucast probe in NUD_INVALID\n"); | 378 | if (!(neigh->nud_state & NUD_VALID)) |
379 | printk(KERN_DEBUG | ||
380 | "trying to ucast probe in NUD_INVALID\n"); | ||
375 | dst_ha = neigh->ha; | 381 | dst_ha = neigh->ha; |
376 | read_lock_bh(&neigh->lock); | 382 | read_lock_bh(&neigh->lock); |
377 | } else if ((probes -= neigh->parms->app_probes) < 0) { | 383 | } else { |
384 | probes -= neigh->parms->app_probes; | ||
385 | if (probes < 0) { | ||
378 | #ifdef CONFIG_ARPD | 386 | #ifdef CONFIG_ARPD |
379 | neigh_app_ns(neigh); | 387 | neigh_app_ns(neigh); |
380 | #endif | 388 | #endif |
381 | return; | 389 | return; |
390 | } | ||
382 | } | 391 | } |
383 | 392 | ||
384 | arp_send(ARPOP_REQUEST, ETH_P_ARP, target, dev, saddr, | 393 | arp_send(ARPOP_REQUEST, ETH_P_ARP, target, dev, saddr, |
@@ -451,7 +460,8 @@ static int arp_filter(__be32 sip, __be32 tip, struct net_device *dev) | |||
451 | * is allowed to use this function, it is scheduled to be removed. --ANK | 460 | * is allowed to use this function, it is scheduled to be removed. --ANK |
452 | */ | 461 | */ |
453 | 462 | ||
454 | static int arp_set_predefined(int addr_hint, unsigned char * haddr, __be32 paddr, struct net_device * dev) | 463 | static int arp_set_predefined(int addr_hint, unsigned char *haddr, |
464 | __be32 paddr, struct net_device *dev) | ||
455 | { | 465 | { |
456 | switch (addr_hint) { | 466 | switch (addr_hint) { |
457 | case RTN_LOCAL: | 467 | case RTN_LOCAL: |
@@ -483,7 +493,8 @@ int arp_find(unsigned char *haddr, struct sk_buff *skb) | |||
483 | 493 | ||
484 | paddr = skb_rtable(skb)->rt_gateway; | 494 | paddr = skb_rtable(skb)->rt_gateway; |
485 | 495 | ||
486 | if (arp_set_predefined(inet_addr_type(dev_net(dev), paddr), haddr, paddr, dev)) | 496 | if (arp_set_predefined(inet_addr_type(dev_net(dev), paddr), haddr, |
497 | paddr, dev)) | ||
487 | return 0; | 498 | return 0; |
488 | 499 | ||
489 | n = __neigh_lookup(&arp_tbl, &paddr, dev, 1); | 500 | n = __neigh_lookup(&arp_tbl, &paddr, dev, 1); |
@@ -515,13 +526,14 @@ int arp_bind_neighbour(struct dst_entry *dst) | |||
515 | return -EINVAL; | 526 | return -EINVAL; |
516 | if (n == NULL) { | 527 | if (n == NULL) { |
517 | __be32 nexthop = ((struct rtable *)dst)->rt_gateway; | 528 | __be32 nexthop = ((struct rtable *)dst)->rt_gateway; |
518 | if (dev->flags&(IFF_LOOPBACK|IFF_POINTOPOINT)) | 529 | if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) |
519 | nexthop = 0; | 530 | nexthop = 0; |
520 | n = __neigh_lookup_errno( | 531 | n = __neigh_lookup_errno( |
521 | #if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) | 532 | #if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) |
522 | dev->type == ARPHRD_ATM ? clip_tbl_hook : | 533 | dev->type == ARPHRD_ATM ? |
534 | clip_tbl_hook : | ||
523 | #endif | 535 | #endif |
524 | &arp_tbl, &nexthop, dev); | 536 | &arp_tbl, &nexthop, dev); |
525 | if (IS_ERR(n)) | 537 | if (IS_ERR(n)) |
526 | return PTR_ERR(n); | 538 | return PTR_ERR(n); |
527 | dst->neighbour = n; | 539 | dst->neighbour = n; |
@@ -543,8 +555,8 @@ static inline int arp_fwd_proxy(struct in_device *in_dev, | |||
543 | 555 | ||
544 | if (!IN_DEV_PROXY_ARP(in_dev)) | 556 | if (!IN_DEV_PROXY_ARP(in_dev)) |
545 | return 0; | 557 | return 0; |
546 | 558 | imi = IN_DEV_MEDIUM_ID(in_dev); | |
547 | if ((imi = IN_DEV_MEDIUM_ID(in_dev)) == 0) | 559 | if (imi == 0) |
548 | return 1; | 560 | return 1; |
549 | if (imi == -1) | 561 | if (imi == -1) |
550 | return 0; | 562 | return 0; |
@@ -685,7 +697,7 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip, | |||
685 | arp->ar_pln = 4; | 697 | arp->ar_pln = 4; |
686 | arp->ar_op = htons(type); | 698 | arp->ar_op = htons(type); |
687 | 699 | ||
688 | arp_ptr=(unsigned char *)(arp+1); | 700 | arp_ptr = (unsigned char *)(arp + 1); |
689 | 701 | ||
690 | memcpy(arp_ptr, src_hw, dev->addr_len); | 702 | memcpy(arp_ptr, src_hw, dev->addr_len); |
691 | arp_ptr += dev->addr_len; | 703 | arp_ptr += dev->addr_len; |
@@ -735,9 +747,8 @@ void arp_send(int type, int ptype, __be32 dest_ip, | |||
735 | 747 | ||
736 | skb = arp_create(type, ptype, dest_ip, dev, src_ip, | 748 | skb = arp_create(type, ptype, dest_ip, dev, src_ip, |
737 | dest_hw, src_hw, target_hw); | 749 | dest_hw, src_hw, target_hw); |
738 | if (skb == NULL) { | 750 | if (skb == NULL) |
739 | return; | 751 | return; |
740 | } | ||
741 | 752 | ||
742 | arp_xmit(skb); | 753 | arp_xmit(skb); |
743 | } | 754 | } |
@@ -815,7 +826,7 @@ static int arp_process(struct sk_buff *skb) | |||
815 | /* | 826 | /* |
816 | * Extract fields | 827 | * Extract fields |
817 | */ | 828 | */ |
818 | arp_ptr= (unsigned char *)(arp+1); | 829 | arp_ptr = (unsigned char *)(arp + 1); |
819 | sha = arp_ptr; | 830 | sha = arp_ptr; |
820 | arp_ptr += dev->addr_len; | 831 | arp_ptr += dev->addr_len; |
821 | memcpy(&sip, arp_ptr, 4); | 832 | memcpy(&sip, arp_ptr, 4); |
@@ -869,16 +880,17 @@ static int arp_process(struct sk_buff *skb) | |||
869 | addr_type = rt->rt_type; | 880 | addr_type = rt->rt_type; |
870 | 881 | ||
871 | if (addr_type == RTN_LOCAL) { | 882 | if (addr_type == RTN_LOCAL) { |
872 | int dont_send = 0; | 883 | int dont_send; |
873 | 884 | ||
874 | if (!dont_send) | 885 | dont_send = arp_ignore(in_dev, sip, tip); |
875 | dont_send |= arp_ignore(in_dev,sip,tip); | ||
876 | if (!dont_send && IN_DEV_ARPFILTER(in_dev)) | 886 | if (!dont_send && IN_DEV_ARPFILTER(in_dev)) |
877 | dont_send |= arp_filter(sip,tip,dev); | 887 | dont_send |= arp_filter(sip, tip, dev); |
878 | if (!dont_send) { | 888 | if (!dont_send) { |
879 | n = neigh_event_ns(&arp_tbl, sha, &sip, dev); | 889 | n = neigh_event_ns(&arp_tbl, sha, &sip, dev); |
880 | if (n) { | 890 | if (n) { |
881 | arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha); | 891 | arp_send(ARPOP_REPLY, ETH_P_ARP, sip, |
892 | dev, tip, sha, dev->dev_addr, | ||
893 | sha); | ||
882 | neigh_release(n); | 894 | neigh_release(n); |
883 | } | 895 | } |
884 | } | 896 | } |
@@ -887,8 +899,7 @@ static int arp_process(struct sk_buff *skb) | |||
887 | if (addr_type == RTN_UNICAST && | 899 | if (addr_type == RTN_UNICAST && |
888 | (arp_fwd_proxy(in_dev, dev, rt) || | 900 | (arp_fwd_proxy(in_dev, dev, rt) || |
889 | arp_fwd_pvlan(in_dev, dev, rt, sip, tip) || | 901 | arp_fwd_pvlan(in_dev, dev, rt, sip, tip) || |
890 | pneigh_lookup(&arp_tbl, net, &tip, dev, 0))) | 902 | pneigh_lookup(&arp_tbl, net, &tip, dev, 0))) { |
891 | { | ||
892 | n = neigh_event_ns(&arp_tbl, sha, &sip, dev); | 903 | n = neigh_event_ns(&arp_tbl, sha, &sip, dev); |
893 | if (n) | 904 | if (n) |
894 | neigh_release(n); | 905 | neigh_release(n); |
@@ -896,9 +907,12 @@ static int arp_process(struct sk_buff *skb) | |||
896 | if (NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED || | 907 | if (NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED || |
897 | skb->pkt_type == PACKET_HOST || | 908 | skb->pkt_type == PACKET_HOST || |
898 | in_dev->arp_parms->proxy_delay == 0) { | 909 | in_dev->arp_parms->proxy_delay == 0) { |
899 | arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha); | 910 | arp_send(ARPOP_REPLY, ETH_P_ARP, sip, |
911 | dev, tip, sha, dev->dev_addr, | ||
912 | sha); | ||
900 | } else { | 913 | } else { |
901 | pneigh_enqueue(&arp_tbl, in_dev->arp_parms, skb); | 914 | pneigh_enqueue(&arp_tbl, |
915 | in_dev->arp_parms, skb); | ||
902 | return 0; | 916 | return 0; |
903 | } | 917 | } |
904 | goto out; | 918 | goto out; |
@@ -939,7 +953,8 @@ static int arp_process(struct sk_buff *skb) | |||
939 | if (arp->ar_op != htons(ARPOP_REPLY) || | 953 | if (arp->ar_op != htons(ARPOP_REPLY) || |
940 | skb->pkt_type != PACKET_HOST) | 954 | skb->pkt_type != PACKET_HOST) |
941 | state = NUD_STALE; | 955 | state = NUD_STALE; |
942 | neigh_update(n, sha, state, override ? NEIGH_UPDATE_F_OVERRIDE : 0); | 956 | neigh_update(n, sha, state, |
957 | override ? NEIGH_UPDATE_F_OVERRIDE : 0); | ||
943 | neigh_release(n); | 958 | neigh_release(n); |
944 | } | 959 | } |
945 | 960 | ||
@@ -975,7 +990,8 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev, | |||
975 | arp->ar_pln != 4) | 990 | arp->ar_pln != 4) |
976 | goto freeskb; | 991 | goto freeskb; |
977 | 992 | ||
978 | if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) | 993 | skb = skb_share_check(skb, GFP_ATOMIC); |
994 | if (skb == NULL) | ||
979 | goto out_of_mem; | 995 | goto out_of_mem; |
980 | 996 | ||
981 | memset(NEIGH_CB(skb), 0, sizeof(struct neighbour_cb)); | 997 | memset(NEIGH_CB(skb), 0, sizeof(struct neighbour_cb)); |
@@ -1019,7 +1035,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r, | |||
1019 | return -EINVAL; | 1035 | return -EINVAL; |
1020 | if (!dev && (r->arp_flags & ATF_COM)) { | 1036 | if (!dev && (r->arp_flags & ATF_COM)) { |
1021 | dev = dev_getbyhwaddr(net, r->arp_ha.sa_family, | 1037 | dev = dev_getbyhwaddr(net, r->arp_ha.sa_family, |
1022 | r->arp_ha.sa_data); | 1038 | r->arp_ha.sa_data); |
1023 | if (!dev) | 1039 | if (!dev) |
1024 | return -ENODEV; | 1040 | return -ENODEV; |
1025 | } | 1041 | } |
@@ -1033,7 +1049,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r, | |||
1033 | } | 1049 | } |
1034 | 1050 | ||
1035 | static int arp_req_set(struct net *net, struct arpreq *r, | 1051 | static int arp_req_set(struct net *net, struct arpreq *r, |
1036 | struct net_device * dev) | 1052 | struct net_device *dev) |
1037 | { | 1053 | { |
1038 | __be32 ip; | 1054 | __be32 ip; |
1039 | struct neighbour *neigh; | 1055 | struct neighbour *neigh; |
@@ -1046,10 +1062,11 @@ static int arp_req_set(struct net *net, struct arpreq *r, | |||
1046 | if (r->arp_flags & ATF_PERM) | 1062 | if (r->arp_flags & ATF_PERM) |
1047 | r->arp_flags |= ATF_COM; | 1063 | r->arp_flags |= ATF_COM; |
1048 | if (dev == NULL) { | 1064 | if (dev == NULL) { |
1049 | struct flowi fl = { .nl_u = { .ip4_u = { .daddr = ip, | 1065 | struct flowi fl = { .nl_u.ip4_u = { .daddr = ip, |
1050 | .tos = RTO_ONLINK } } }; | 1066 | .tos = RTO_ONLINK } }; |
1051 | struct rtable * rt; | 1067 | struct rtable *rt; |
1052 | if ((err = ip_route_output_key(net, &rt, &fl)) != 0) | 1068 | err = ip_route_output_key(net, &rt, &fl); |
1069 | if (err != 0) | ||
1053 | return err; | 1070 | return err; |
1054 | dev = rt->dst.dev; | 1071 | dev = rt->dst.dev; |
1055 | ip_rt_put(rt); | 1072 | ip_rt_put(rt); |
@@ -1083,9 +1100,9 @@ static int arp_req_set(struct net *net, struct arpreq *r, | |||
1083 | unsigned state = NUD_STALE; | 1100 | unsigned state = NUD_STALE; |
1084 | if (r->arp_flags & ATF_PERM) | 1101 | if (r->arp_flags & ATF_PERM) |
1085 | state = NUD_PERMANENT; | 1102 | state = NUD_PERMANENT; |
1086 | err = neigh_update(neigh, (r->arp_flags&ATF_COM) ? | 1103 | err = neigh_update(neigh, (r->arp_flags & ATF_COM) ? |
1087 | r->arp_ha.sa_data : NULL, state, | 1104 | r->arp_ha.sa_data : NULL, state, |
1088 | NEIGH_UPDATE_F_OVERRIDE| | 1105 | NEIGH_UPDATE_F_OVERRIDE | |
1089 | NEIGH_UPDATE_F_ADMIN); | 1106 | NEIGH_UPDATE_F_ADMIN); |
1090 | neigh_release(neigh); | 1107 | neigh_release(neigh); |
1091 | } | 1108 | } |
@@ -1094,12 +1111,12 @@ static int arp_req_set(struct net *net, struct arpreq *r, | |||
1094 | 1111 | ||
1095 | static unsigned arp_state_to_flags(struct neighbour *neigh) | 1112 | static unsigned arp_state_to_flags(struct neighbour *neigh) |
1096 | { | 1113 | { |
1097 | unsigned flags = 0; | ||
1098 | if (neigh->nud_state&NUD_PERMANENT) | 1114 | if (neigh->nud_state&NUD_PERMANENT) |
1099 | flags = ATF_PERM|ATF_COM; | 1115 | return ATF_PERM | ATF_COM; |
1100 | else if (neigh->nud_state&NUD_VALID) | 1116 | else if (neigh->nud_state&NUD_VALID) |
1101 | flags = ATF_COM; | 1117 | return ATF_COM; |
1102 | return flags; | 1118 | else |
1119 | return 0; | ||
1103 | } | 1120 | } |
1104 | 1121 | ||
1105 | /* | 1122 | /* |
@@ -1142,7 +1159,7 @@ static int arp_req_delete_public(struct net *net, struct arpreq *r, | |||
1142 | } | 1159 | } |
1143 | 1160 | ||
1144 | static int arp_req_delete(struct net *net, struct arpreq *r, | 1161 | static int arp_req_delete(struct net *net, struct arpreq *r, |
1145 | struct net_device * dev) | 1162 | struct net_device *dev) |
1146 | { | 1163 | { |
1147 | int err; | 1164 | int err; |
1148 | __be32 ip; | 1165 | __be32 ip; |
@@ -1153,10 +1170,11 @@ static int arp_req_delete(struct net *net, struct arpreq *r, | |||
1153 | 1170 | ||
1154 | ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; | 1171 | ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; |
1155 | if (dev == NULL) { | 1172 | if (dev == NULL) { |
1156 | struct flowi fl = { .nl_u = { .ip4_u = { .daddr = ip, | 1173 | struct flowi fl = { .nl_u.ip4_u = { .daddr = ip, |
1157 | .tos = RTO_ONLINK } } }; | 1174 | .tos = RTO_ONLINK } }; |
1158 | struct rtable * rt; | 1175 | struct rtable *rt; |
1159 | if ((err = ip_route_output_key(net, &rt, &fl)) != 0) | 1176 | err = ip_route_output_key(net, &rt, &fl); |
1177 | if (err != 0) | ||
1160 | return err; | 1178 | return err; |
1161 | dev = rt->dst.dev; | 1179 | dev = rt->dst.dev; |
1162 | ip_rt_put(rt); | 1180 | ip_rt_put(rt); |
@@ -1166,7 +1184,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r, | |||
1166 | err = -ENXIO; | 1184 | err = -ENXIO; |
1167 | neigh = neigh_lookup(&arp_tbl, &ip, dev); | 1185 | neigh = neigh_lookup(&arp_tbl, &ip, dev); |
1168 | if (neigh) { | 1186 | if (neigh) { |
1169 | if (neigh->nud_state&~NUD_NOARP) | 1187 | if (neigh->nud_state & ~NUD_NOARP) |
1170 | err = neigh_update(neigh, NULL, NUD_FAILED, | 1188 | err = neigh_update(neigh, NULL, NUD_FAILED, |
1171 | NEIGH_UPDATE_F_OVERRIDE| | 1189 | NEIGH_UPDATE_F_OVERRIDE| |
1172 | NEIGH_UPDATE_F_ADMIN); | 1190 | NEIGH_UPDATE_F_ADMIN); |
@@ -1186,24 +1204,24 @@ int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg) | |||
1186 | struct net_device *dev = NULL; | 1204 | struct net_device *dev = NULL; |
1187 | 1205 | ||
1188 | switch (cmd) { | 1206 | switch (cmd) { |
1189 | case SIOCDARP: | 1207 | case SIOCDARP: |
1190 | case SIOCSARP: | 1208 | case SIOCSARP: |
1191 | if (!capable(CAP_NET_ADMIN)) | 1209 | if (!capable(CAP_NET_ADMIN)) |
1192 | return -EPERM; | 1210 | return -EPERM; |
1193 | case SIOCGARP: | 1211 | case SIOCGARP: |
1194 | err = copy_from_user(&r, arg, sizeof(struct arpreq)); | 1212 | err = copy_from_user(&r, arg, sizeof(struct arpreq)); |
1195 | if (err) | 1213 | if (err) |
1196 | return -EFAULT; | 1214 | return -EFAULT; |
1197 | break; | 1215 | break; |
1198 | default: | 1216 | default: |
1199 | return -EINVAL; | 1217 | return -EINVAL; |
1200 | } | 1218 | } |
1201 | 1219 | ||
1202 | if (r.arp_pa.sa_family != AF_INET) | 1220 | if (r.arp_pa.sa_family != AF_INET) |
1203 | return -EPFNOSUPPORT; | 1221 | return -EPFNOSUPPORT; |
1204 | 1222 | ||
1205 | if (!(r.arp_flags & ATF_PUBL) && | 1223 | if (!(r.arp_flags & ATF_PUBL) && |
1206 | (r.arp_flags & (ATF_NETMASK|ATF_DONTPUB))) | 1224 | (r.arp_flags & (ATF_NETMASK | ATF_DONTPUB))) |
1207 | return -EINVAL; | 1225 | return -EINVAL; |
1208 | if (!(r.arp_flags & ATF_NETMASK)) | 1226 | if (!(r.arp_flags & ATF_NETMASK)) |
1209 | ((struct sockaddr_in *)&r.arp_netmask)->sin_addr.s_addr = | 1227 | ((struct sockaddr_in *)&r.arp_netmask)->sin_addr.s_addr = |
@@ -1211,7 +1229,8 @@ int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg) | |||
1211 | rtnl_lock(); | 1229 | rtnl_lock(); |
1212 | if (r.arp_dev[0]) { | 1230 | if (r.arp_dev[0]) { |
1213 | err = -ENODEV; | 1231 | err = -ENODEV; |
1214 | if ((dev = __dev_get_by_name(net, r.arp_dev)) == NULL) | 1232 | dev = __dev_get_by_name(net, r.arp_dev); |
1233 | if (dev == NULL) | ||
1215 | goto out; | 1234 | goto out; |
1216 | 1235 | ||
1217 | /* Mmmm... It is wrong... ARPHRD_NETROM==0 */ | 1236 | /* Mmmm... It is wrong... ARPHRD_NETROM==0 */ |
@@ -1243,7 +1262,8 @@ out: | |||
1243 | return err; | 1262 | return err; |
1244 | } | 1263 | } |
1245 | 1264 | ||
1246 | static int arp_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) | 1265 | static int arp_netdev_event(struct notifier_block *this, unsigned long event, |
1266 | void *ptr) | ||
1247 | { | 1267 | { |
1248 | struct net_device *dev = ptr; | 1268 | struct net_device *dev = ptr; |
1249 | 1269 | ||
@@ -1311,12 +1331,13 @@ static char *ax2asc2(ax25_address *a, char *buf) | |||
1311 | for (n = 0, s = buf; n < 6; n++) { | 1331 | for (n = 0, s = buf; n < 6; n++) { |
1312 | c = (a->ax25_call[n] >> 1) & 0x7F; | 1332 | c = (a->ax25_call[n] >> 1) & 0x7F; |
1313 | 1333 | ||
1314 | if (c != ' ') *s++ = c; | 1334 | if (c != ' ') |
1335 | *s++ = c; | ||
1315 | } | 1336 | } |
1316 | 1337 | ||
1317 | *s++ = '-'; | 1338 | *s++ = '-'; |
1318 | 1339 | n = (a->ax25_call[6] >> 1) & 0x0F; | |
1319 | if ((n = ((a->ax25_call[6] >> 1) & 0x0F)) > 9) { | 1340 | if (n > 9) { |
1320 | *s++ = '1'; | 1341 | *s++ = '1'; |
1321 | n -= 10; | 1342 | n -= 10; |
1322 | } | 1343 | } |
@@ -1325,10 +1346,9 @@ static char *ax2asc2(ax25_address *a, char *buf) | |||
1325 | *s++ = '\0'; | 1346 | *s++ = '\0'; |
1326 | 1347 | ||
1327 | if (*buf == '\0' || *buf == '-') | 1348 | if (*buf == '\0' || *buf == '-') |
1328 | return "*"; | 1349 | return "*"; |
1329 | 1350 | ||
1330 | return buf; | 1351 | return buf; |
1331 | |||
1332 | } | 1352 | } |
1333 | #endif /* CONFIG_AX25 */ | 1353 | #endif /* CONFIG_AX25 */ |
1334 | 1354 | ||
@@ -1408,10 +1428,10 @@ static void *arp_seq_start(struct seq_file *seq, loff_t *pos) | |||
1408 | /* ------------------------------------------------------------------------ */ | 1428 | /* ------------------------------------------------------------------------ */ |
1409 | 1429 | ||
1410 | static const struct seq_operations arp_seq_ops = { | 1430 | static const struct seq_operations arp_seq_ops = { |
1411 | .start = arp_seq_start, | 1431 | .start = arp_seq_start, |
1412 | .next = neigh_seq_next, | 1432 | .next = neigh_seq_next, |
1413 | .stop = neigh_seq_stop, | 1433 | .stop = neigh_seq_stop, |
1414 | .show = arp_seq_show, | 1434 | .show = arp_seq_show, |
1415 | }; | 1435 | }; |
1416 | 1436 | ||
1417 | static int arp_seq_open(struct inode *inode, struct file *file) | 1437 | static int arp_seq_open(struct inode *inode, struct file *file) |