Main Page | Class List | File List | Class Members | File Members

arp.c File Reference

#include <linux/types.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/config.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/errno.h>
#include <linux/in.h>
#include <linux/mm.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/fddidevice.h>
#include <linux/if_arp.h>
#include <linux/trdevice.h>
#include <linux/skbuff.h>
#include <linux/proc_fs.h>
#include <linux/stat.h>
#include <linux/init.h>
#include <net/ip.h>
#include <net/icmp.h>
#include <net/route.h>
#include <net/protocol.h>
#include <net/tcp.h>
#include <net/sock.h>
#include <net/arp.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#include <linux/netfilter_arp.h>

Go to the source code of this file.

Functions

u32 arp_hash (const void *pkey, const struct net_device *dev)
int arp_constructor (struct neighbour *neigh)
void arp_solicit (struct neighbour *neigh, struct sk_buff *skb)
void arp_error_report (struct neighbour *neigh, struct sk_buff *skb)
void parp_redo (struct sk_buff *skb)
int arp_mc_map (u32 addr, u8 *haddr, struct net_device *dev, int dir)
int arp_filter (__u32 sip, __u32 tip, struct net_device *dev)
int arp_set_predefined (int addr_hint, unsigned char *haddr, u32 paddr, struct net_device *dev)
int arp_find (unsigned char *haddr, struct sk_buff *skb)
int arp_bind_neighbour (struct dst_entry *dst)
int arp_fwd_proxy (struct in_device *in_dev, struct rtable *rt)
void arp_send (int type, int ptype, u32 dest_ip, struct net_device *dev, u32 src_ip, unsigned char *dest_hw, unsigned char *src_hw, unsigned char *target_hw)
int arp_process (struct sk_buff *skb)
int arp_rcv (struct sk_buff *skb, struct net_device *dev, struct packet_type *pt)
int arp_req_set (struct arpreq *r, struct net_device *dev)
unsigned arp_state_to_flags (struct neighbour *neigh)
int arp_req_get (struct arpreq *r, struct net_device *dev)
int arp_req_delete (struct arpreq *r, struct net_device *dev)
int arp_ioctl (unsigned int cmd, void *arg)
int arp_get_info (char *buffer, char **start, off_t offset, int length)
int arp_netdev_event (struct notifier_block *this, unsigned long event, void *ptr)
void arp_ifdown (struct net_device *dev)
void __init arp_init (void)

Variables

neigh_ops arp_generic_ops
neigh_ops arp_hh_ops
neigh_ops arp_direct_ops
neigh_ops arp_broken_ops
neigh_table arp_tbl
notifier_block arp_netdev_notifier
packet_type arp_packet_type


Function Documentation

int arp_bind_neighbour struct dst_entry dst  ) 
 

Definition at line 430 of file arp.c.

References __neigh_lookup_errno(), arp_tbl, clip_tbl_hook, dst_entry::dev, and dst_entry::neighbour.

Referenced by ip_rt_redirect(), and rt_intern_hash().

00431 { 00432 struct net_device *dev = dst->dev; 00433 struct neighbour *n = dst->neighbour; 00434 00435 if (dev == NULL) 00436 return -EINVAL; 00437 if (n == NULL) { 00438 u32 nexthop = ((struct rtable*)dst)->rt_gateway; 00439 if (dev->flags&(IFF_LOOPBACK|IFF_POINTOPOINT)) 00440 nexthop = 0; 00441 n = __neigh_lookup_errno( 00442 #if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) 00443 dev->type == ARPHRD_ATM ? clip_tbl_hook : 00444 #endif 00445 &arp_tbl, &nexthop, dev); 00446 if (IS_ERR(n)) 00447 return PTR_ERR(n); 00448 dst->neighbour = n; 00449 } 00450 return 0; 00451 }

int arp_constructor struct neighbour neigh  )  [static]
 

Definition at line 228 of file arp.c.

References arp_broken_ops, arp_direct_ops, arp_generic_ops, arp_hh_ops, arp_mc_map(), neigh_ops::connected_output, neighbour::dev, neighbour::ha, in_dev_get(), in_dev_put(), inet_addr_type(), NUD_NOARP, neighbour::nud_state, NUD_VALID, neighbour::ops, neigh_ops::output, neighbour::output, neighbour::parms, neighbour::primary_key, neigh_ops::queue_xmit, and neighbour::type.

00229 { 00230 u32 addr = *(u32*)neigh->primary_key; 00231 struct net_device *dev = neigh->dev; 00232 struct in_device *in_dev = in_dev_get(dev); 00233 00234 if (in_dev == NULL) 00235 return -EINVAL; 00236 00237 neigh->type = inet_addr_type(addr); 00238 if (in_dev->arp_parms) 00239 neigh->parms = in_dev->arp_parms; 00240 00241 in_dev_put(in_dev); 00242 00243 if (dev->hard_header == NULL) { 00244 neigh->nud_state = NUD_NOARP; 00245 neigh->ops = &arp_direct_ops; 00246 neigh->output = neigh->ops->queue_xmit; 00247 } else { 00248 /* Good devices (checked by reading texts, but only Ethernet is 00249 tested) 00250 00251 ARPHRD_ETHER: (ethernet, apfddi) 00252 ARPHRD_FDDI: (fddi) 00253 ARPHRD_IEEE802: (tr) 00254 ARPHRD_METRICOM: (strip) 00255 ARPHRD_ARCNET: 00256 etc. etc. etc. 00257 00258 ARPHRD_IPDDP will also work, if author repairs it. 00259 I did not it, because this driver does not work even 00260 in old paradigm. 00261 */ 00262 00263 #if 1 00264 /* So... these "amateur" devices are hopeless. 00265 The only thing, that I can say now: 00266 It is very sad that we need to keep ugly obsolete 00267 code to make them happy. 00268 00269 They should be moved to more reasonable state, now 00270 they use rebuild_header INSTEAD OF hard_start_xmit!!! 00271 Besides that, they are sort of out of date 00272 (a lot of redundant clones/copies, useless in 2.1), 00273 I wonder why people believe that they work. 00274 */ 00275 switch (dev->type) { 00276 default: 00277 break; 00278 case ARPHRD_ROSE: 00279 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) 00280 case ARPHRD_AX25: 00281 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE) 00282 case ARPHRD_NETROM: 00283 #endif 00284 neigh->ops = &arp_broken_ops; 00285 neigh->output = neigh->ops->output; 00286 return 0; 00287 #endif 00288 ;} 00289 #endif 00290 if (neigh->type == RTN_MULTICAST) { 00291 neigh->nud_state = NUD_NOARP; 00292 arp_mc_map(addr, neigh->ha, dev, 1); 00293 } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { 00294 neigh->nud_state = NUD_NOARP; 00295 memcpy(neigh->ha, dev->dev_addr, dev->addr_len); 00296 } else if (neigh->type == RTN_BROADCAST || dev->flags&IFF_POINTOPOINT) { 00297 neigh->nud_state = NUD_NOARP; 00298 memcpy(neigh->ha, dev->broadcast, dev->addr_len); 00299 } 00300 if (dev->hard_header_cache) 00301 neigh->ops = &arp_hh_ops; 00302 else 00303 neigh->ops = &arp_generic_ops; 00304 if (neigh->nud_state&NUD_VALID) 00305 neigh->output = neigh->ops->connected_output; 00306 else 00307 neigh->output = neigh->ops->output; 00308 } 00309 return 0; 00310 }

void arp_error_report struct neighbour neigh,
struct sk_buff skb
[static]
 

Definition at line 312 of file arp.c.

References dst_link_failure(), and kfree_skb().

00313 { 00314 dst_link_failure(skb); 00315 kfree_skb(skb); 00316 }

int arp_filter __u32  sip,
__u32  tip,
struct net_device dev
[static]
 

Definition at line 349 of file arp.c.

References ip_route_output(), ip_rt_put(), and NET_INC_STATS_BH.

Referenced by arp_process().

00350 { 00351 struct rtable *rt; 00352 int flag = 0; 00353 /*unsigned long now; */ 00354 00355 if (ip_route_output(&rt, sip, tip, 0, 0) < 0) 00356 return 1; 00357 if (rt->u.dst.dev != dev) { 00358 NET_INC_STATS_BH(ArpFilter); 00359 flag = 1; 00360 } 00361 ip_rt_put(rt); 00362 return flag; 00363 }

int arp_find unsigned char *  haddr,
struct sk_buff skb
 

Definition at line 394 of file arp.c.

References __neigh_lookup(), arp_set_predefined(), arp_tbl, sk_buff::dev, sk_buff::dst, inet_addr_type(), kfree_skb(), neigh_event_send(), neigh_release(), and NUD_VALID.

00395 { 00396 struct net_device *dev = skb->dev; 00397 u32 paddr; 00398 struct neighbour *n; 00399 00400 if (!skb->dst) { 00401 printk(KERN_DEBUG "arp_find is called with dst==NULL\n"); 00402 kfree_skb(skb); 00403 return 1; 00404 } 00405 00406 paddr = ((struct rtable*)skb->dst)->rt_gateway; 00407 00408 if (arp_set_predefined(inet_addr_type(paddr), haddr, paddr, dev)) 00409 return 0; 00410 00411 n = __neigh_lookup(&arp_tbl, &paddr, dev, 1); 00412 00413 if (n) { 00414 n->used = jiffies; 00415 if (n->nud_state&NUD_VALID || neigh_event_send(n, skb) == 0) { 00416 read_lock_bh(&n->lock); 00417 memcpy(haddr, n->ha, dev->addr_len); 00418 read_unlock_bh(&n->lock); 00419 neigh_release(n); 00420 return 0; 00421 } 00422 neigh_release(n); 00423 } else 00424 kfree_skb(skb); 00425 return 1; 00426 }

int arp_fwd_proxy struct in_device in_dev,
struct rtable rt
[inline, static]
 

Definition at line 457 of file arp.c.

References in_dev_get(), IN_DEV_MEDIUM_ID, IN_DEV_PROXY_ARP, in_dev_put(), and rtable::u.

Referenced by arp_process().

00458 { 00459 struct in_device *out_dev; 00460 int imi, omi = -1; 00461 00462 if (!IN_DEV_PROXY_ARP(in_dev)) 00463 return 0; 00464 00465 if ((imi = IN_DEV_MEDIUM_ID(in_dev)) == 0) 00466 return 1; 00467 if (imi == -1) 00468 return 0; 00469 00470 /* place to check for proxy_arp for routes */ 00471 00472 if ((out_dev = in_dev_get(rt->u.dst.dev)) != NULL) { 00473 omi = IN_DEV_MEDIUM_ID(out_dev); 00474 in_dev_put(out_dev); 00475 } 00476 return (omi != imi && omi != -1); 00477 }

int arp_get_info char *  buffer,
char **  start,
off_t  offset,
int  length
[static]
 

Definition at line 1097 of file arp.c.

Referenced by arp_init().

01097 { return 0; }

u32 arp_hash const void *  pkey,
const struct net_device dev
[static]
 

Definition at line 215 of file arp.c.

References net_device::ifindex, and NEIGH_HASHMASK.

00216 { 00217 u32 hash_val; 00218 00219 hash_val = *(u32*)pkey; 00220 hash_val ^= (hash_val>>16); 00221 hash_val ^= hash_val>>8; 00222 hash_val ^= hash_val>>3; 00223 hash_val = (hash_val^dev->ifindex)&NEIGH_HASHMASK; 00224 00225 return hash_val; 00226 }

void arp_ifdown struct net_device dev  ) 
 

Definition at line 1241 of file arp.c.

References arp_tbl, and neigh_ifdown().

Referenced by fib_disable_ip().

01242 { 01243 neigh_ifdown(&arp_tbl, dev); 01244 }

void __init arp_init void   ) 
 

Definition at line 1257 of file arp.c.

References arp_get_info(), arp_netdev_notifier, arp_packet_type, arp_tbl, dev_add_pack(), neigh_sysctl_register(), neigh_table_init(), neigh_table::parms, and register_netdevice_notifier().

Referenced by inet_init().

01258 { 01259 neigh_table_init(&arp_tbl); 01260 01261 dev_add_pack(&arp_packet_type); 01262 01263 proc_net_create ("arp", 0, arp_get_info); 01264 01265 #ifdef CONFIG_SYSCTL 01266 neigh_sysctl_register(NULL, &arp_tbl.parms, NET_IPV4, NET_IPV4_NEIGH, "ipv4"); 01267 #endif 01268 register_netdevice_notifier(&arp_netdev_notifier); 01269 }

int arp_ioctl unsigned int  cmd,
void *  arg
 

Definition at line 1029 of file arp.c.

References __dev_get_by_name(), arp_req_delete(), arp_req_get(), arp_req_set(), rtnl_lock(), and rtnl_unlock().

Referenced by inet_ioctl().

01030 { 01031 int err; 01032 struct arpreq r; 01033 struct net_device * dev = NULL; 01034 01035 switch(cmd) { 01036 case SIOCDARP: 01037 case SIOCSARP: 01038 if (!capable(CAP_NET_ADMIN)) 01039 return -EPERM; 01040 case SIOCGARP: 01041 err = copy_from_user(&r, arg, sizeof(struct arpreq)); 01042 if (err) 01043 return -EFAULT; 01044 break; 01045 default: 01046 return -EINVAL; 01047 } 01048 01049 if (r.arp_pa.sa_family != AF_INET) 01050 return -EPFNOSUPPORT; 01051 01052 if (!(r.arp_flags & ATF_PUBL) && 01053 (r.arp_flags & (ATF_NETMASK|ATF_DONTPUB))) 01054 return -EINVAL; 01055 if (!(r.arp_flags & ATF_NETMASK)) 01056 ((struct sockaddr_in *)&r.arp_netmask)->sin_addr.s_addr=htonl(0xFFFFFFFFUL); 01057 01058 rtnl_lock(); 01059 if (r.arp_dev[0]) { 01060 err = -ENODEV; 01061 if ((dev = __dev_get_by_name(r.arp_dev)) == NULL) 01062 goto out; 01063 01064 /* Mmmm... It is wrong... ARPHRD_NETROM==0 */ 01065 if (!r.arp_ha.sa_family) 01066 r.arp_ha.sa_family = dev->type; 01067 err = -EINVAL; 01068 if ((r.arp_flags & ATF_COM) && r.arp_ha.sa_family != dev->type) 01069 goto out; 01070 } else if (cmd == SIOCGARP) { 01071 err = -ENODEV; 01072 goto out; 01073 } 01074 01075 switch(cmd) { 01076 case SIOCDARP: 01077 err = arp_req_delete(&r, dev); 01078 break; 01079 case SIOCSARP: 01080 err = arp_req_set(&r, dev); 01081 break; 01082 case SIOCGARP: 01083 err = arp_req_get(&r, dev); 01084 if (!err && copy_to_user(arg, &r, sizeof(r))) 01085 err = -EFAULT; 01086 break; 01087 } 01088 out: 01089 rtnl_unlock(); 01090 return err; 01091 }

int arp_mc_map u32  addr,
u8 *  haddr,
struct net_device dev,
int  dir
 

Definition at line 194 of file arp.c.

References net_device::addr_len, net_device::broadcast, ip_eth_mc_map(), ip_tr_mc_map(), and net_device::type.

Referenced by arp_constructor(), arp_set_predefined(), ip_mc_filter_add(), and ip_mc_filter_del().

00195 { 00196 switch (dev->type) { 00197 case ARPHRD_ETHER: 00198 case ARPHRD_FDDI: 00199 case ARPHRD_IEEE802: 00200 ip_eth_mc_map(addr, haddr); 00201 return 0; 00202 case ARPHRD_IEEE802_TR: 00203 ip_tr_mc_map(addr, haddr); 00204 return 0; 00205 default: 00206 if (dir) { 00207 memcpy(haddr, dev->broadcast, dev->addr_len); 00208 return 0; 00209 } 00210 } 00211 return -EINVAL; 00212 }

int arp_netdev_event struct notifier_block *  this,
unsigned long  event,
void *  ptr
[static]
 

Definition at line 1217 of file arp.c.

References arp_tbl, neigh_changeaddr(), and rt_cache_flush().

01218 { 01219 struct net_device *dev = ptr; 01220 01221 switch (event) { 01222 case NETDEV_CHANGEADDR: 01223 neigh_changeaddr(&arp_tbl, dev); 01224 rt_cache_flush(0); 01225 break; 01226 default: 01227 break; 01228 } 01229 01230 return NOTIFY_DONE; 01231 }

int arp_process struct sk_buff skb  ) 
 

Definition at line 608 of file arp.c.

References __neigh_lookup(), arp_filter(), arp_fwd_proxy(), arp_send(), arp_tbl, AX25_P_IP, sk_buff::dev, sk_buff::dst, IN_DEV_ARPFILTER, IN_DEV_FORWARD, in_dev_get(), in_dev_put(), inet_addr_type(), ip_route_input(), kfree_skb(), LOOPBACK, MULTICAST, neigh_event_ns(), neigh_release(), neigh_update(), sk_buff::nh, NUD_REACHABLE, NUD_STALE, sk_buff::pkt_type, pneigh_enqueue(), pneigh_lookup(), and sk_buff::stamp.

Referenced by arp_rcv().

00609 { 00610 struct net_device *dev = skb->dev; 00611 struct in_device *in_dev = in_dev_get(dev); 00612 struct arphdr *arp; 00613 unsigned char *arp_ptr; 00614 struct rtable *rt; 00615 unsigned char *sha, *tha; 00616 u32 sip, tip; 00617 u16 dev_type = dev->type; 00618 int addr_type; 00619 struct neighbour *n; 00620 00621 /* arp_rcv below verifies the ARP header, verifies the device 00622 * is ARP'able, and linearizes the SKB (if needed). 00623 */ 00624 00625 if (in_dev == NULL) 00626 goto out; 00627 00628 arp = skb->nh.arph; 00629 arp_ptr= (unsigned char *)(arp+1); 00630 00631 switch (dev_type) { 00632 default: 00633 if (arp->ar_pro != htons(ETH_P_IP)) 00634 goto out; 00635 if (htons(dev_type) != arp->ar_hrd) 00636 goto out; 00637 break; 00638 #ifdef CONFIG_NET_ETHERNET 00639 case ARPHRD_ETHER: 00640 /* 00641 * ETHERNET devices will accept ARP hardware types of either 00642 * 1 (Ethernet) or 6 (IEEE 802.2). 00643 */ 00644 if (arp->ar_hrd != htons(ARPHRD_ETHER) && 00645 arp->ar_hrd != htons(ARPHRD_IEEE802)) 00646 goto out; 00647 if (arp->ar_pro != htons(ETH_P_IP)) 00648 goto out; 00649 break; 00650 #endif 00651 #ifdef CONFIG_TR 00652 case ARPHRD_IEEE802_TR: 00653 /* 00654 * Token ring devices will accept ARP hardware types of either 00655 * 1 (Ethernet) or 6 (IEEE 802.2). 00656 */ 00657 if (arp->ar_hrd != htons(ARPHRD_ETHER) && 00658 arp->ar_hrd != htons(ARPHRD_IEEE802)) 00659 goto out; 00660 if (arp->ar_pro != htons(ETH_P_IP)) 00661 goto out; 00662 break; 00663 #endif 00664 #ifdef CONFIG_FDDI 00665 case ARPHRD_FDDI: 00666 /* 00667 * According to RFC 1390, FDDI devices should accept ARP hardware types 00668 * of 1 (Ethernet). However, to be more robust, we'll accept hardware 00669 * types of either 1 (Ethernet) or 6 (IEEE 802.2). 00670 */ 00671 if (arp->ar_hrd != htons(ARPHRD_ETHER) && 00672 arp->ar_hrd != htons(ARPHRD_IEEE802)) 00673 goto out; 00674 if (arp->ar_pro != htons(ETH_P_IP)) 00675 goto out; 00676 break; 00677 #endif 00678 #ifdef CONFIG_NET_FC 00679 case ARPHRD_IEEE802: 00680 /* 00681 * According to RFC 2625, Fibre Channel devices (which are IEEE 00682 * 802 devices) should accept ARP hardware types of 6 (IEEE 802) 00683 * and 1 (Ethernet). 00684 */ 00685 if (arp->ar_hrd != htons(ARPHRD_ETHER) && 00686 arp->ar_hrd != htons(ARPHRD_IEEE802)) 00687 goto out; 00688 if (arp->ar_pro != htons(ETH_P_IP)) 00689 goto out; 00690 break; 00691 #endif 00692 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) 00693 case ARPHRD_AX25: 00694 if (arp->ar_pro != htons(AX25_P_IP)) 00695 goto out; 00696 if (arp->ar_hrd != htons(ARPHRD_AX25)) 00697 goto out; 00698 break; 00699 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE) 00700 case ARPHRD_NETROM: 00701 if (arp->ar_pro != htons(AX25_P_IP)) 00702 goto out; 00703 if (arp->ar_hrd != htons(ARPHRD_NETROM)) 00704 goto out; 00705 break; 00706 #endif 00707 #endif 00708 } 00709 00710 /* Understand only these message types */ 00711 00712 if (arp->ar_op != htons(ARPOP_REPLY) && 00713 arp->ar_op != htons(ARPOP_REQUEST)) 00714 goto out; 00715 00716 /* 00717 * Extract fields 00718 */ 00719 sha=arp_ptr; 00720 arp_ptr += dev->addr_len; 00721 memcpy(&sip, arp_ptr, 4); 00722 arp_ptr += 4; 00723 tha=arp_ptr; 00724 arp_ptr += dev->addr_len; 00725 memcpy(&tip, arp_ptr, 4); 00726 /* 00727 * Check for bad requests for 127.x.x.x and requests for multicast 00728 * addresses. If this is one such, delete it. 00729 */ 00730 if (LOOPBACK(tip) || MULTICAST(tip)) 00731 goto out; 00732 00733 /* 00734 * Special case: We must set Frame Relay source Q.922 address 00735 */ 00736 if (dev_type == ARPHRD_DLCI) 00737 sha = dev->broadcast; 00738 00739 /* 00740 * Process entry. The idea here is we want to send a reply if it is a 00741 * request for us or if it is a request for someone else that we hold 00742 * a proxy for. We want to add an entry to our cache if it is a reply 00743 * to us or if it is a request for our address. 00744 * (The assumption for this last is that if someone is requesting our 00745 * address, they are probably intending to talk to us, so it saves time 00746 * if we cache their address. Their address is also probably not in 00747 * our cache, since ours is not in their cache.) 00748 * 00749 * Putting this another way, we only care about replies if they are to 00750 * us, in which case we add them to the cache. For requests, we care 00751 * about those for us and those for our proxies. We reply to both, 00752 * and in the case of requests for us we add the requester to the arp 00753 * cache. 00754 */ 00755 00756 /* Special case: IPv4 duplicate address detection packet (RFC2131) */ 00757 if (sip == 0) { 00758 if (arp->ar_op == htons(ARPOP_REQUEST) && 00759 inet_addr_type(tip) == RTN_LOCAL) 00760 arp_send(ARPOP_REPLY,ETH_P_ARP,tip,dev,tip,sha,dev->dev_addr,dev->dev_addr); 00761 goto out; 00762 } 00763 00764 if (arp->ar_op == htons(ARPOP_REQUEST) && 00765 ip_route_input(skb, tip, sip, 0, dev) == 0) { 00766 00767 rt = (struct rtable*)skb->dst; 00768 addr_type = rt->rt_type; 00769 00770 if (addr_type == RTN_LOCAL) { 00771 n = neigh_event_ns(&arp_tbl, sha, &sip, dev); 00772 if (n) { 00773 int dont_send = 0; 00774 if (IN_DEV_ARPFILTER(in_dev)) 00775 dont_send |= arp_filter(sip,tip,dev); 00776 if (!dont_send) 00777 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha); 00778 00779 neigh_release(n); 00780 } 00781 goto out; 00782 } else if (IN_DEV_FORWARD(in_dev)) { 00783 if ((rt->rt_flags&RTCF_DNAT) || 00784 (addr_type == RTN_UNICAST && rt->u.dst.dev != dev && 00785 (arp_fwd_proxy(in_dev, rt) || pneigh_lookup(&arp_tbl, &tip, dev, 0)))) { 00786 n = neigh_event_ns(&arp_tbl, sha, &sip, dev); 00787 if (n) 00788 neigh_release(n); 00789 00790 if (skb->stamp.tv_sec == 0 || 00791 skb->pkt_type == PACKET_HOST || 00792 in_dev->arp_parms->proxy_delay == 0) { 00793 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha); 00794 } else { 00795 pneigh_enqueue(&arp_tbl, in_dev->arp_parms, skb); 00796 in_dev_put(in_dev); 00797 return 0; 00798 } 00799 goto out; 00800 } 00801 } 00802 } 00803 00804 /* Update our ARP tables */ 00805 00806 n = __neigh_lookup(&arp_tbl, &sip, dev, 0); 00807 00808 #ifdef CONFIG_IP_ACCEPT_UNSOLICITED_ARP 00809 /* Unsolicited ARP is not accepted by default. 00810 It is possible, that this option should be enabled for some 00811 devices (strip is candidate) 00812 */ 00813 if (n == NULL && 00814 arp->ar_op == htons(ARPOP_REPLY) && 00815 inet_addr_type(sip) == RTN_UNICAST) 00816 n = __neigh_lookup(&arp_tbl, &sip, dev, -1); 00817 #endif 00818 00819 if (n) { 00820 int state = NUD_REACHABLE; 00821 int override = 0; 00822 00823 /* If several different ARP replies follows back-to-back, 00824 use the FIRST one. It is possible, if several proxy 00825 agents are active. Taking the first reply prevents 00826 arp trashing and chooses the fastest router. 00827 */ 00828 if (jiffies - n->updated >= n->parms->locktime) 00829 override = 1; 00830 00831 /* Broadcast replies and request packets 00832 do not assert neighbour reachability. 00833 */ 00834 if (arp->ar_op != htons(ARPOP_REPLY) || 00835 skb->pkt_type != PACKET_HOST) 00836 state = NUD_STALE; 00837 neigh_update(n, sha, state, override, 1); 00838 neigh_release(n); 00839 } 00840 00841 out: 00842 if (in_dev) 00843 in_dev_put(in_dev); 00844 kfree_skb(skb); 00845 return 0; 00846 }

int arp_rcv struct sk_buff skb,
struct net_device dev,
struct packet_type pt
 

Definition at line 853 of file arp.c.

References net_device::addr_len, arp_process(), net_device::flags, kfree_skb(), NF_HOOK, sk_buff::nh, sk_buff::pkt_type, pskb_may_pull(), and skb_share_check().

Referenced by parp_redo().

00854 { 00855 struct arphdr *arp; 00856 00857 /* ARP header, plus 2 device addresses, plus 2 IP addresses. */ 00858 if (!pskb_may_pull(skb, (sizeof(struct arphdr) + 00859 (2 * dev->addr_len) + 00860 (2 * sizeof(u32))))) 00861 goto freeskb; 00862 00863 arp = skb->nh.arph; 00864 if (arp->ar_hln != dev->addr_len || 00865 dev->flags & IFF_NOARP || 00866 skb->pkt_type == PACKET_OTHERHOST || 00867 skb->pkt_type == PACKET_LOOPBACK || 00868 arp->ar_pln != 4) 00869 goto freeskb; 00870 00871 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) 00872 goto out_of_mem; 00873 00874 return NF_HOOK(NF_ARP, NF_ARP_IN, skb, dev, NULL, arp_process); 00875 00876 freeskb: 00877 kfree_skb(skb); 00878 out_of_mem: 00879 return 0; 00880 }

int arp_req_delete struct arpreq *  r,
struct net_device dev
 

Definition at line 982 of file arp.c.

References __in_dev_get(), arp_tbl, in_device::cnf, ip_route_output(), ip_rt_put(), neigh_lookup(), neigh_release(), neigh_update(), NUD_FAILED, NUD_NOARP, pneigh_delete(), ipv4_devconf::proxy_arp, and RTO_ONLINK.

Referenced by arp_ioctl().

00983 { 00984 int err; 00985 u32 ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; 00986 struct neighbour *neigh; 00987 00988 if (r->arp_flags & ATF_PUBL) { 00989 u32 mask = ((struct sockaddr_in *) &r->arp_netmask)->sin_addr.s_addr; 00990 if (mask == 0xFFFFFFFF) 00991 return pneigh_delete(&arp_tbl, &ip, dev); 00992 if (mask == 0) { 00993 if (dev == NULL) { 00994 ipv4_devconf.proxy_arp = 0; 00995 return 0; 00996 } 00997 if (__in_dev_get(dev)) { 00998 __in_dev_get(dev)->cnf.proxy_arp = 0; 00999 return 0; 01000 } 01001 return -ENXIO; 01002 } 01003 return -EINVAL; 01004 } 01005 01006 if (dev == NULL) { 01007 struct rtable * rt; 01008 if ((err = ip_route_output(&rt, ip, 0, RTO_ONLINK, 0)) != 0) 01009 return err; 01010 dev = rt->u.dst.dev; 01011 ip_rt_put(rt); 01012 if (!dev) 01013 return -EINVAL; 01014 } 01015 err = -ENXIO; 01016 neigh = neigh_lookup(&arp_tbl, &ip, dev); 01017 if (neigh) { 01018 if (neigh->nud_state&~NUD_NOARP) 01019 err = neigh_update(neigh, NULL, NUD_FAILED, 1, 0); 01020 neigh_release(neigh); 01021 } 01022 return err; 01023 }

int arp_req_get struct arpreq *  r,
struct net_device dev
[static]
 

Definition at line 962 of file arp.c.

References net_device::addr_len, arp_state_to_flags(), arp_tbl, net_device::name, neigh_lookup(), neigh_release(), and net_device::type.

Referenced by arp_ioctl().

00963 { 00964 u32 ip = ((struct sockaddr_in *) &r->arp_pa)->sin_addr.s_addr; 00965 struct neighbour *neigh; 00966 int err = -ENXIO; 00967 00968 neigh = neigh_lookup(&arp_tbl, &ip, dev); 00969 if (neigh) { 00970 read_lock_bh(&neigh->lock); 00971 memcpy(r->arp_ha.sa_data, neigh->ha, dev->addr_len); 00972 r->arp_flags = arp_state_to_flags(neigh); 00973 read_unlock_bh(&neigh->lock); 00974 r->arp_ha.sa_family = dev->type; 00975 strncpy(r->arp_dev, dev->name, sizeof(r->arp_dev)); 00976 neigh_release(neigh); 00977 err = 0; 00978 } 00979 return err; 00980 }

int arp_req_set struct arpreq *  r,
struct net_device dev
 

Definition at line 890 of file arp.c.

References __in_dev_get(), __neigh_lookup_errno(), arp_tbl, in_device::cnf, dev_getbyhwaddr(), ip_route_output(), ip_rt_put(), neigh_release(), neigh_update(), NUD_PERMANENT, NUD_STALE, pneigh_lookup(), ipv4_devconf::proxy_arp, RTO_ONLINK, and net_device::type.

Referenced by arp_ioctl().

00891 { 00892 u32 ip = ((struct sockaddr_in *) &r->arp_pa)->sin_addr.s_addr; 00893 struct neighbour *neigh; 00894 int err; 00895 00896 if (r->arp_flags&ATF_PUBL) { 00897 u32 mask = ((struct sockaddr_in *) &r->arp_netmask)->sin_addr.s_addr; 00898 if (mask && mask != 0xFFFFFFFF) 00899 return -EINVAL; 00900 if (!dev && (r->arp_flags & ATF_COM)) { 00901 dev = dev_getbyhwaddr(r->arp_ha.sa_family, r->arp_ha.sa_data); 00902 if (!dev) 00903 return -ENODEV; 00904 } 00905 if (mask) { 00906 if (pneigh_lookup(&arp_tbl, &ip, dev, 1) == NULL) 00907 return -ENOBUFS; 00908 return 0; 00909 } 00910 if (dev == NULL) { 00911 ipv4_devconf.proxy_arp = 1; 00912 return 0; 00913 } 00914 if (__in_dev_get(dev)) { 00915 __in_dev_get(dev)->cnf.proxy_arp = 1; 00916 return 0; 00917 } 00918 return -ENXIO; 00919 } 00920 00921 if (r->arp_flags & ATF_PERM) 00922 r->arp_flags |= ATF_COM; 00923 if (dev == NULL) { 00924 struct rtable * rt; 00925 if ((err = ip_route_output(&rt, ip, 0, RTO_ONLINK, 0)) != 0) 00926 return err; 00927 dev = rt->u.dst.dev; 00928 ip_rt_put(rt); 00929 if (!dev) 00930 return -EINVAL; 00931 } 00932 if (r->arp_ha.sa_family != dev->type) 00933 return -EINVAL; 00934 00935 neigh = __neigh_lookup_errno(&arp_tbl, &ip, dev); 00936 err = PTR_ERR(neigh); 00937 if (!IS_ERR(neigh)) { 00938 unsigned state = NUD_STALE; 00939 if (r->arp_flags & ATF_PERM) 00940 state = NUD_PERMANENT; 00941 err = neigh_update(neigh, (r->arp_flags&ATF_COM) ? 00942 r->arp_ha.sa_data : NULL, state, 1, 0); 00943 neigh_release(neigh); 00944 } 00945 return err; 00946 }

void arp_send int  type,
int  ptype,
u32  dest_ip,
struct net_device dev,
u32  src_ip,
unsigned char *  dest_hw,
unsigned char *  src_hw,
unsigned char *  target_hw
 

Definition at line 488 of file arp.c.

References net_device::addr_len, alloc_skb(), AX25_P_IP, net_device::broadcast, net_device::dev_addr, dev_queue_xmit(), net_device::flags, net_device::hard_header, net_device::hard_header_len, kfree_skb(), NF_HOOK, skb_put(), skb_reserve(), and net_device::type.

Referenced by arp_process(), and arp_solicit().

00492 { 00493 struct sk_buff *skb; 00494 struct arphdr *arp; 00495 unsigned char *arp_ptr; 00496 00497 /* 00498 * No arp on this interface. 00499 */ 00500 00501 if (dev->flags&IFF_NOARP) 00502 return; 00503 00504 /* 00505 * Allocate a buffer 00506 */ 00507 00508 skb = alloc_skb(sizeof(struct arphdr)+ 2*(dev->addr_len+4) 00509 + dev->hard_header_len + 15, GFP_ATOMIC); 00510 if (skb == NULL) 00511 return; 00512 00513 skb_reserve(skb, (dev->hard_header_len+15)&~15); 00514 skb->nh.raw = skb->data; 00515 arp = (struct arphdr *) skb_put(skb,sizeof(struct arphdr) + 2*(dev->addr_len+4)); 00516 skb->dev = dev; 00517 skb->protocol = htons (ETH_P_ARP); 00518 if (src_hw == NULL) 00519 src_hw = dev->dev_addr; 00520 if (dest_hw == NULL) 00521 dest_hw = dev->broadcast; 00522 00523 /* 00524 * Fill the device header for the ARP frame 00525 */ 00526 if (dev->hard_header && 00527 dev->hard_header(skb,dev,ptype,dest_hw,src_hw,skb->len) < 0) 00528 goto out; 00529 00530 /* 00531 * Fill out the arp protocol part. 00532 * 00533 * The arp hardware type should match the device type, except for FDDI, 00534 * which (according to RFC 1390) should always equal 1 (Ethernet). 00535 */ 00536 /* 00537 * Exceptions everywhere. AX.25 uses the AX.25 PID value not the 00538 * DIX code for the protocol. Make these device structure fields. 00539 */ 00540 switch (dev->type) { 00541 default: 00542 arp->ar_hrd = htons(dev->type); 00543 arp->ar_pro = htons(ETH_P_IP); 00544 break; 00545 00546 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) 00547 case ARPHRD_AX25: 00548 arp->ar_hrd = htons(ARPHRD_AX25); 00549 arp->ar_pro = htons(AX25_P_IP); 00550 break; 00551 00552 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE) 00553 case ARPHRD_NETROM: 00554 arp->ar_hrd = htons(ARPHRD_NETROM); 00555 arp->ar_pro = htons(AX25_P_IP); 00556 break; 00557 #endif 00558 #endif 00559 00560 #ifdef CONFIG_FDDI 00561 case ARPHRD_FDDI: 00562 arp->ar_hrd = htons(ARPHRD_ETHER); 00563 arp->ar_pro = htons(ETH_P_IP); 00564 break; 00565 #endif 00566 #ifdef CONFIG_TR 00567 case ARPHRD_IEEE802_TR: 00568 arp->ar_hrd = htons(ARPHRD_IEEE802); 00569 arp->ar_pro = htons(ETH_P_IP); 00570 break; 00571 #endif 00572 } 00573 00574 arp->ar_hln = dev->addr_len; 00575 arp->ar_pln = 4; 00576 arp->ar_op = htons(type); 00577 00578 arp_ptr=(unsigned char *)(arp+1); 00579 00580 memcpy(arp_ptr, src_hw, dev->addr_len); 00581 arp_ptr+=dev->addr_len; 00582 memcpy(arp_ptr, &src_ip,4); 00583 arp_ptr+=4; 00584 if (target_hw != NULL) 00585 memcpy(arp_ptr, target_hw, dev->addr_len); 00586 else 00587 memset(arp_ptr, 0, dev->addr_len); 00588 arp_ptr+=dev->addr_len; 00589 memcpy(arp_ptr, &dest_ip, 4); 00590 00591 /* Send it off, maybe filter it using firewalling first. */ 00592 NF_HOOK(NF_ARP, NF_ARP_OUT, skb, NULL, dev, dev_queue_xmit); 00593 return; 00594 00595 out: 00596 kfree_skb(skb); 00597 }

int arp_set_predefined int  addr_hint,
unsigned char *  haddr,
u32  paddr,
struct net_device dev
[static]
 

Definition at line 376 of file arp.c.

References net_device::addr_len, arp_mc_map(), net_device::broadcast, and net_device::dev_addr.

Referenced by arp_find().

00377 { 00378 switch (addr_hint) { 00379 case RTN_LOCAL: 00380 printk(KERN_DEBUG "ARP: arp called for own IP address\n"); 00381 memcpy(haddr, dev->dev_addr, dev->addr_len); 00382 return 1; 00383 case RTN_MULTICAST: 00384 arp_mc_map(paddr, haddr, dev, 1); 00385 return 1; 00386 case RTN_BROADCAST: 00387 memcpy(haddr, dev->broadcast, dev->addr_len); 00388 return 1; 00389 } 00390 return 0; 00391 }

void arp_solicit struct neighbour neigh,
struct sk_buff skb
[static]
 

Definition at line 318 of file arp.c.

References neigh_parms::app_probes, arp_send(), neighbour::dev, neighbour::ha, inet_addr_type(), inet_select_addr(), neighbour::lock, neigh_app_ns(), sk_buff::nh, neighbour::nud_state, NUD_VALID, neighbour::parms, neighbour::primary_key, neighbour::probes, and neigh_parms::ucast_probes.

00319 { 00320 u32 saddr; 00321 u8 *dst_ha = NULL; 00322 struct net_device *dev = neigh->dev; 00323 u32 target = *(u32*)neigh->primary_key; 00324 int probes = atomic_read(&neigh->probes); 00325 00326 if (skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL) 00327 saddr = skb->nh.iph->saddr; 00328 else 00329 saddr = inet_select_addr(dev, target, RT_SCOPE_LINK); 00330 00331 if ((probes -= neigh->parms->ucast_probes) < 0) { 00332 if (!(neigh->nud_state&NUD_VALID)) 00333 printk(KERN_DEBUG "trying to ucast probe in NUD_INVALID\n"); 00334 dst_ha = neigh->ha; 00335 read_lock_bh(&neigh->lock); 00336 } else if ((probes -= neigh->parms->app_probes) < 0) { 00337 #ifdef CONFIG_ARPD 00338 neigh_app_ns(neigh); 00339 #endif 00340 return; 00341 } 00342 00343 arp_send(ARPOP_REQUEST, ETH_P_ARP, target, dev, saddr, 00344 dst_ha, dev->dev_addr, NULL); 00345 if (dst_ha) 00346 read_unlock_bh(&neigh->lock); 00347 }

unsigned arp_state_to_flags struct neighbour neigh  )  [static]
 

Definition at line 948 of file arp.c.

References NUD_PERMANENT, neighbour::nud_state, and NUD_VALID.

Referenced by arp_req_get().

00949 { 00950 unsigned flags = 0; 00951 if (neigh->nud_state&NUD_PERMANENT) 00952 flags = ATF_PERM|ATF_COM; 00953 else if (neigh->nud_state&NUD_VALID) 00954 flags = ATF_COM; 00955 return flags; 00956 }

void parp_redo struct sk_buff skb  )  [static]
 

Definition at line 599 of file arp.c.

References arp_rcv(), and sk_buff::dev.

00600 { 00601 arp_rcv(skb, skb->dev, NULL); 00602 }


Variable Documentation

struct neigh_ops arp_broken_ops
 

Initial value:

{ family: AF_INET, solicit: arp_solicit, error_report: arp_error_report, output: neigh_compat_output, connected_output: neigh_compat_output, hh_output: dev_queue_xmit, queue_xmit: dev_queue_xmit, }
Definition at line 155 of file arp.c.

Referenced by arp_constructor().

struct neigh_ops arp_direct_ops [static]
 

Initial value:

{ family: AF_INET, output: dev_queue_xmit, connected_output: dev_queue_xmit, hh_output: dev_queue_xmit, queue_xmit: dev_queue_xmit, }
Definition at line 147 of file arp.c.

Referenced by arp_constructor().

struct neigh_ops arp_generic_ops [static]
 

Initial value:

{ family: AF_INET, solicit: arp_solicit, error_report: arp_error_report, output: neigh_resolve_output, connected_output: neigh_connected_output, hh_output: dev_queue_xmit, queue_xmit: dev_queue_xmit, }
Definition at line 127 of file arp.c.

Referenced by arp_constructor().

struct neigh_ops arp_hh_ops [static]
 

Initial value:

{ family: AF_INET, solicit: arp_solicit, error_report: arp_error_report, output: neigh_resolve_output, connected_output: neigh_resolve_output, hh_output: dev_queue_xmit, queue_xmit: dev_queue_xmit, }
Definition at line 137 of file arp.c.

Referenced by arp_constructor().

struct notifier_block arp_netdev_notifier
 

Initial value:

{ .notifier_call = arp_netdev_event, }
Definition at line 1233 of file arp.c.

Referenced by arp_init().

struct packet_type arp_packet_type [static]
 

Initial value:

{ type: __constant_htons(ETH_P_ARP), func: arp_rcv, data: (void*) 1, }
Definition at line 1251 of file arp.c.

Referenced by arp_init().

struct neigh_table arp_tbl
 

Initial value:

{ family: AF_INET, entry_size: sizeof(struct neighbour) + 4, key_len: 4, hash: arp_hash, constructor: arp_constructor, proxy_redo: parp_redo, id: "arp_cache", parms: { tbl: &arp_tbl, base_reachable_time: 30 * HZ, retrans_time: 1 * HZ, gc_staletime: 60 * HZ, reachable_time: 30 * HZ, delay_probe_time: 5 * HZ, queue_len: 3, ucast_probes: 3, mcast_probes: 3, anycast_delay: 1 * HZ, proxy_delay: (8 * HZ) / 10, proxy_qlen: 64, locktime: 1 * HZ, }, gc_interval: 30 * HZ, gc_thresh1: 128, gc_thresh2: 512, gc_thresh3: 1024, }
Definition at line 165 of file arp.c.

Referenced by arp_bind_neighbour(), arp_find(), arp_ifdown(), arp_init(), arp_netdev_event(), arp_process(), arp_req_delete(), arp_req_get(), arp_req_set(), fib_detect_death(), inetdev_destroy(), and inetdev_init().


Generated on Wed Dec 1 21:25:34 2004 for Linux 2.4.23 Networking by doxygen 1.3.8