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

inetdevice.h File Reference

Go to the source code of this file.

Classes

struct  ipv4_devconf
struct  in_device
struct  in_ifaddr

Defines

#define IN_DEV_FORWARD(in_dev)   ((in_dev)->cnf.forwarding)
#define IN_DEV_MFORWARD(in_dev)   (ipv4_devconf.mc_forwarding && (in_dev)->cnf.mc_forwarding)
#define IN_DEV_RPFILTER(in_dev)   (ipv4_devconf.rp_filter && (in_dev)->cnf.rp_filter)
#define IN_DEV_SOURCE_ROUTE(in_dev)   (ipv4_devconf.accept_source_route && (in_dev)->cnf.accept_source_route)
#define IN_DEV_BOOTP_RELAY(in_dev)   (ipv4_devconf.bootp_relay && (in_dev)->cnf.bootp_relay)
#define IN_DEV_LOG_MARTIANS(in_dev)   (ipv4_devconf.log_martians || (in_dev)->cnf.log_martians)
#define IN_DEV_PROXY_ARP(in_dev)   (ipv4_devconf.proxy_arp || (in_dev)->cnf.proxy_arp)
#define IN_DEV_SHARED_MEDIA(in_dev)   (ipv4_devconf.shared_media || (in_dev)->cnf.shared_media)
#define IN_DEV_TX_REDIRECTS(in_dev)   (ipv4_devconf.send_redirects || (in_dev)->cnf.send_redirects)
#define IN_DEV_SEC_REDIRECTS(in_dev)   (ipv4_devconf.secure_redirects || (in_dev)->cnf.secure_redirects)
#define IN_DEV_IDTAG(in_dev)   ((in_dev)->cnf.tag)
#define IN_DEV_MEDIUM_ID(in_dev)   ((in_dev)->cnf.medium_id)
#define IN_DEV_RX_REDIRECTS(in_dev)
#define IN_DEV_ARPFILTER(in_dev)   (ipv4_devconf.arp_filter || (in_dev)->cnf.arp_filter)
#define IN_DEV_LOOP(in_dev)   ((in_dev)->cnf.loop)
#define for_primary_ifa(in_dev)
#define for_ifa(in_dev)
#define endfor_ifa(in_dev)   }
#define __in_dev_put(idev)   atomic_dec(&(idev)->refcnt)
#define in_dev_hold(idev)   atomic_inc(&(idev)->refcnt)

Functions

int register_inetaddr_notifier (struct notifier_block *nb)
int unregister_inetaddr_notifier (struct notifier_block *nb)
net_deviceip_dev_find (u32 addr)
int inet_addr_onlink (struct in_device *in_dev, u32 a, u32 b)
int devinet_ioctl (unsigned int cmd, void *)
void devinet_init (void)
in_deviceinetdev_init (struct net_device *dev)
in_deviceinetdev_by_index (int)
u32 inet_select_addr (const struct net_device *dev, u32 dst, int scope)
in_ifaddrinet_ifa_byprefix (struct in_device *in_dev, u32 prefix, u32 mask)
void inet_forward_change (void)
__inline__ int inet_ifa_match (u32 addr, struct in_ifaddr *ifa)
__inline__ int bad_mask (u32 mask, u32 addr)
__inline__ struct in_devicein_dev_get (const struct net_device *dev)
__inline__ struct in_device__in_dev_get (const struct net_device *dev)
void in_dev_finish_destroy (struct in_device *idev)
__inline__ void in_dev_put (struct in_device *idev)
__inline__ __u32 inet_make_mask (int logmask)
__inline__ int inet_mask_len (__u32 mask)

Variables

ipv4_devconf ipv4_devconf
rwlock_t inetdev_lock


Define Documentation

#define __in_dev_put idev   )     atomic_dec(&(idev)->refcnt)
 

Definition at line 161 of file inetdevice.h.

Referenced by inet_free_ifa(), inet_rtm_deladdr(), ip_mc_down(), and ip_mc_find_dev().

#define endfor_ifa in_dev   )     }
 

Definition at line 128 of file inetdevice.h.

Referenced by fib_netdev_event(), inet_addr_onlink(), inet_ifa_byprefix(), and inet_select_addr().

#define for_ifa in_dev   ) 
 

Value:

{ struct in_ifaddr *ifa; \ for (ifa = (in_dev)->ifa_list; ifa; ifa = ifa->ifa_next)
Definition at line 124 of file inetdevice.h.

Referenced by fib_netdev_event().

#define for_primary_ifa in_dev   ) 
 

Value:

{ struct in_ifaddr *ifa; \ for (ifa = (in_dev)->ifa_list; ifa && !(ifa->ifa_flags&IFA_F_SECONDARY); ifa = ifa->ifa_next)
Definition at line 121 of file inetdevice.h.

Referenced by inet_addr_onlink(), inet_ifa_byprefix(), and inet_select_addr().

#define IN_DEV_ARPFILTER in_dev   )     (ipv4_devconf.arp_filter || (in_dev)->cnf.arp_filter)
 

Definition at line 71 of file inetdevice.h.

Referenced by arp_process().

#define IN_DEV_BOOTP_RELAY in_dev   )     (ipv4_devconf.bootp_relay && (in_dev)->cnf.bootp_relay)
 

Definition at line 55 of file inetdevice.h.

#define IN_DEV_FORWARD in_dev   )     ((in_dev)->cnf.forwarding)
 

Definition at line 51 of file inetdevice.h.

Referenced by arp_process(), icmp_address_reply(), and ip_route_input_slow().

#define in_dev_hold idev   )     atomic_inc(&(idev)->refcnt)
 

Definition at line 162 of file inetdevice.h.

Referenced by inet_rtm_newaddr(), inet_set_ifa(), inetdev_event(), inetdev_init(), and ip_mc_inc_group().

#define IN_DEV_IDTAG in_dev   )     ((in_dev)->cnf.tag)
 

Definition at line 62 of file inetdevice.h.

#define IN_DEV_LOG_MARTIANS in_dev   )     (ipv4_devconf.log_martians || (in_dev)->cnf.log_martians)
 

Definition at line 57 of file inetdevice.h.

Referenced by icmp_address_reply(), ip_rcv_finish(), ip_route_input_slow(), ip_rt_redirect(), and ip_rt_send_redirect().

#define IN_DEV_LOOP in_dev   )     ((in_dev)->cnf.loop)
 

Definition at line 72 of file inetdevice.h.

Referenced by fib_validate_source(), and ip_route_output_slow().

#define IN_DEV_MEDIUM_ID in_dev   )     ((in_dev)->cnf.medium_id)
 

Definition at line 63 of file inetdevice.h.

Referenced by arp_fwd_proxy().

#define IN_DEV_MFORWARD in_dev   )     (ipv4_devconf.mc_forwarding && (in_dev)->cnf.mc_forwarding)
 

Definition at line 52 of file inetdevice.h.

Referenced by ip_route_input(), ip_route_input_mc(), and ip_route_output_slow().

#define IN_DEV_PROXY_ARP in_dev   )     (ipv4_devconf.proxy_arp || (in_dev)->cnf.proxy_arp)
 

Definition at line 58 of file inetdevice.h.

Referenced by arp_fwd_proxy().

#define IN_DEV_RPFILTER in_dev   )     (ipv4_devconf.rp_filter && (in_dev)->cnf.rp_filter)
 

Definition at line 53 of file inetdevice.h.

Referenced by fib_validate_source().

#define IN_DEV_RX_REDIRECTS in_dev   ) 
 

Value:

((IN_DEV_FORWARD(in_dev) && \ (ipv4_devconf.accept_redirects && (in_dev)->cnf.accept_redirects)) \ || (!IN_DEV_FORWARD(in_dev) && \ (ipv4_devconf.accept_redirects || (in_dev)->cnf.accept_redirects)))
Definition at line 65 of file inetdevice.h.

Referenced by ip_rt_redirect().

#define IN_DEV_SEC_REDIRECTS in_dev   )     (ipv4_devconf.secure_redirects || (in_dev)->cnf.secure_redirects)
 

Definition at line 61 of file inetdevice.h.

Referenced by ip_rt_redirect().

#define IN_DEV_SHARED_MEDIA in_dev   )     (ipv4_devconf.shared_media || (in_dev)->cnf.shared_media)
 

Definition at line 59 of file inetdevice.h.

Referenced by ip_route_input_slow(), and ip_rt_redirect().

#define IN_DEV_SOURCE_ROUTE in_dev   )     (ipv4_devconf.accept_source_route && (in_dev)->cnf.accept_source_route)
 

Definition at line 54 of file inetdevice.h.

Referenced by ip_rcv_finish().

#define IN_DEV_TX_REDIRECTS in_dev   )     (ipv4_devconf.send_redirects || (in_dev)->cnf.send_redirects)
 

Definition at line 60 of file inetdevice.h.

Referenced by ip_rt_send_redirect().


Function Documentation

__inline__ struct in_device* __in_dev_get const struct net_device dev  )  [static]
 

Definition at line 147 of file inetdevice.h.

References net_device::ip_ptr.

Referenced by arp_req_delete(), arp_req_set(), devinet_ioctl(), fib_convert_rtentry(), fib_netdev_event(), fib_validate_source(), inet_dump_ifaddr(), inet_gifconf(), inet_rtm_newaddr(), inet_select_addr(), inet_set_ifa(), inetdev_event(), ip_mc_find_dev(), ip_route_input(), ip_route_output_slow(), ipmr_new_tunnel(), vif_add(), and vif_delete().

00148 { 00149 return (struct in_device*)dev->ip_ptr; 00150 }

__inline__ int bad_mask u32  mask,
u32  addr
[static]
 

Definition at line 111 of file inetdevice.h.

Referenced by devinet_ioctl(), and fib_convert_rtentry().

00112 { 00113 if (addr & (mask = ~mask)) 00114 return 1; 00115 mask = ntohl(mask); 00116 if (mask & (mask+1)) 00117 return 1; 00118 return 0; 00119 }

void devinet_init void   ) 
 

Definition at line 1168 of file devinet.c.

References inet_gifconf(), inet_rtnetlink_table, ip_netdev_notifier, ipv4_devconf_dflt, register_gifconf(), register_netdevice_notifier(), and rtnetlink_links.

Referenced by ip_rt_init().

01169 { 01170 register_gifconf(PF_INET, inet_gifconf); 01171 register_netdevice_notifier(&ip_netdev_notifier); 01172 rtnetlink_links[PF_INET] = inet_rtnetlink_table; 01173 #ifdef CONFIG_SYSCTL 01174 devinet_sysctl.sysctl_header = 01175 register_sysctl_table(devinet_sysctl.devinet_root_dir, 0); 01176 devinet_sysctl_register(NULL, &ipv4_devconf_dflt); 01177 #endif 01178 }

int devinet_ioctl unsigned int  cmd,
void * 
 

Definition at line 459 of file devinet.c.

References __dev_get_by_name(), __in_dev_get(), bad_mask(), dev_change_flags(), dev_load(), inet_abc_len(), inet_alloc_ifa(), inet_del_ifa(), inet_insert_ifa(), inet_make_mask(), inet_mask_len(), inet_set_ifa(), rtnl_lock(), rtnl_unlock(), in_addr::s_addr, sockaddr_in::sin_addr, and sockaddr_in::sin_family.

Referenced by ic_dev_ioctl(), and inet_ioctl().

00460 { 00461 struct ifreq ifr; 00462 struct sockaddr_in sin_orig; 00463 struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr; 00464 struct in_device *in_dev; 00465 struct in_ifaddr **ifap = NULL; 00466 struct in_ifaddr *ifa = NULL; 00467 struct net_device *dev; 00468 char *colon; 00469 int ret = 0; 00470 int tryaddrmatch = 0; 00471 00472 /* 00473 * Fetch the caller's info block into kernel space 00474 */ 00475 00476 if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) 00477 return -EFAULT; 00478 ifr.ifr_name[IFNAMSIZ-1] = 0; 00479 00480 /* save original address for comparison */ 00481 memcpy(&sin_orig, sin, sizeof(*sin)); 00482 00483 colon = strchr(ifr.ifr_name, ':'); 00484 if (colon) 00485 *colon = 0; 00486 00487 #ifdef CONFIG_KMOD 00488 dev_load(ifr.ifr_name); 00489 #endif 00490 00491 switch(cmd) { 00492 case SIOCGIFADDR: /* Get interface address */ 00493 case SIOCGIFBRDADDR: /* Get the broadcast address */ 00494 case SIOCGIFDSTADDR: /* Get the destination address */ 00495 case SIOCGIFNETMASK: /* Get the netmask for the interface */ 00496 /* Note that these ioctls will not sleep, 00497 so that we do not impose a lock. 00498 One day we will be forced to put shlock here (I mean SMP) 00499 */ 00500 tryaddrmatch = (sin_orig.sin_family == AF_INET); 00501 memset(sin, 0, sizeof(*sin)); 00502 sin->sin_family = AF_INET; 00503 break; 00504 00505 case SIOCSIFFLAGS: 00506 if (!capable(CAP_NET_ADMIN)) 00507 return -EACCES; 00508 break; 00509 case SIOCSIFADDR: /* Set interface address (and family) */ 00510 case SIOCSIFBRDADDR: /* Set the broadcast address */ 00511 case SIOCSIFDSTADDR: /* Set the destination address */ 00512 case SIOCSIFNETMASK: /* Set the netmask for the interface */ 00513 if (!capable(CAP_NET_ADMIN)) 00514 return -EACCES; 00515 if (sin->sin_family != AF_INET) 00516 return -EINVAL; 00517 break; 00518 default: 00519 return -EINVAL; 00520 } 00521 00522 dev_probe_lock(); 00523 rtnl_lock(); 00524 00525 if ((dev = __dev_get_by_name(ifr.ifr_name)) == NULL) { 00526 ret = -ENODEV; 00527 goto done; 00528 } 00529 00530 if (colon) 00531 *colon = ':'; 00532 00533 if ((in_dev=__in_dev_get(dev)) != NULL) { 00534 if (tryaddrmatch) { 00535 /* Matthias Andree */ 00536 /* compare label and address (4.4BSD style) */ 00537 /* note: we only do this for a limited set of ioctls 00538 and only if the original address family was AF_INET. 00539 This is checked above. */ 00540 for (ifap=&in_dev->ifa_list; (ifa=*ifap) != NULL; ifap=&ifa->ifa_next) { 00541 if ((strcmp(ifr.ifr_name, ifa->ifa_label) == 0) 00542 && (sin_orig.sin_addr.s_addr == ifa->ifa_address)) { 00543 break; /* found */ 00544 } 00545 } 00546 } 00547 /* we didn't get a match, maybe the application is 00548 4.3BSD-style and passed in junk so we fall back to 00549 comparing just the label */ 00550 if (ifa == NULL) { 00551 for (ifap=&in_dev->ifa_list; (ifa=*ifap) != NULL; ifap=&ifa->ifa_next) 00552 if (strcmp(ifr.ifr_name, ifa->ifa_label) == 0) 00553 break; 00554 } 00555 } 00556 00557 if (ifa == NULL && cmd != SIOCSIFADDR && cmd != SIOCSIFFLAGS) { 00558 ret = -EADDRNOTAVAIL; 00559 goto done; 00560 } 00561 00562 switch(cmd) { 00563 case SIOCGIFADDR: /* Get interface address */ 00564 sin->sin_addr.s_addr = ifa->ifa_local; 00565 goto rarok; 00566 00567 case SIOCGIFBRDADDR: /* Get the broadcast address */ 00568 sin->sin_addr.s_addr = ifa->ifa_broadcast; 00569 goto rarok; 00570 00571 case SIOCGIFDSTADDR: /* Get the destination address */ 00572 sin->sin_addr.s_addr = ifa->ifa_address; 00573 goto rarok; 00574 00575 case SIOCGIFNETMASK: /* Get the netmask for the interface */ 00576 sin->sin_addr.s_addr = ifa->ifa_mask; 00577 goto rarok; 00578 00579 case SIOCSIFFLAGS: 00580 if (colon) { 00581 if (ifa == NULL) { 00582 ret = -EADDRNOTAVAIL; 00583 break; 00584 } 00585 if (!(ifr.ifr_flags&IFF_UP)) 00586 inet_del_ifa(in_dev, ifap, 1); 00587 break; 00588 } 00589 ret = dev_change_flags(dev, ifr.ifr_flags); 00590 break; 00591 00592 case SIOCSIFADDR: /* Set interface address (and family) */ 00593 if (inet_abc_len(sin->sin_addr.s_addr) < 0) { 00594 ret = -EINVAL; 00595 break; 00596 } 00597 00598 if (!ifa) { 00599 if ((ifa = inet_alloc_ifa()) == NULL) { 00600 ret = -ENOBUFS; 00601 break; 00602 } 00603 if (colon) 00604 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); 00605 else 00606 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); 00607 } else { 00608 ret = 0; 00609 if (ifa->ifa_local == sin->sin_addr.s_addr) 00610 break; 00611 inet_del_ifa(in_dev, ifap, 0); 00612 ifa->ifa_broadcast = 0; 00613 ifa->ifa_anycast = 0; 00614 } 00615 00616 ifa->ifa_address = 00617 ifa->ifa_local = sin->sin_addr.s_addr; 00618 00619 if (!(dev->flags&IFF_POINTOPOINT)) { 00620 ifa->ifa_prefixlen = inet_abc_len(ifa->ifa_address); 00621 ifa->ifa_mask = inet_make_mask(ifa->ifa_prefixlen); 00622 if ((dev->flags&IFF_BROADCAST) && ifa->ifa_prefixlen < 31) 00623 ifa->ifa_broadcast = ifa->ifa_address|~ifa->ifa_mask; 00624 } else { 00625 ifa->ifa_prefixlen = 32; 00626 ifa->ifa_mask = inet_make_mask(32); 00627 } 00628 ret = inet_set_ifa(dev, ifa); 00629 break; 00630 00631 case SIOCSIFBRDADDR: /* Set the broadcast address */ 00632 if (ifa->ifa_broadcast != sin->sin_addr.s_addr) { 00633 inet_del_ifa(in_dev, ifap, 0); 00634 ifa->ifa_broadcast = sin->sin_addr.s_addr; 00635 inet_insert_ifa(ifa); 00636 } 00637 break; 00638 00639 case SIOCSIFDSTADDR: /* Set the destination address */ 00640 if (ifa->ifa_address != sin->sin_addr.s_addr) { 00641 if (inet_abc_len(sin->sin_addr.s_addr) < 0) { 00642 ret = -EINVAL; 00643 break; 00644 } 00645 inet_del_ifa(in_dev, ifap, 0); 00646 ifa->ifa_address = sin->sin_addr.s_addr; 00647 inet_insert_ifa(ifa); 00648 } 00649 break; 00650 00651 case SIOCSIFNETMASK: /* Set the netmask for the interface */ 00652 00653 /* 00654 * The mask we set must be legal. 00655 */ 00656 if (bad_mask(sin->sin_addr.s_addr, 0)) { 00657 ret = -EINVAL; 00658 break; 00659 } 00660 00661 if (ifa->ifa_mask != sin->sin_addr.s_addr) { 00662 inet_del_ifa(in_dev, ifap, 0); 00663 ifa->ifa_mask = sin->sin_addr.s_addr; 00664 ifa->ifa_prefixlen = inet_mask_len(ifa->ifa_mask); 00665 inet_insert_ifa(ifa); 00666 } 00667 break; 00668 } 00669 done: 00670 rtnl_unlock(); 00671 dev_probe_unlock(); 00672 return ret; 00673 00674 rarok: 00675 rtnl_unlock(); 00676 dev_probe_unlock(); 00677 if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) 00678 return -EFAULT; 00679 return 0; 00680 }

void in_dev_finish_destroy struct in_device idev  ) 
 

Definition at line 104 of file devinet.c.

References in_device::dead, in_device::dev, dev_put(), in_device::ifa_list, inet_dev_count, and in_device::mc_list.

Referenced by in_dev_put().

00105 { 00106 struct net_device *dev = idev->dev; 00107 00108 BUG_TRAP(idev->ifa_list==NULL); 00109 BUG_TRAP(idev->mc_list==NULL); 00110 #ifdef NET_REFCNT_DEBUG 00111 printk(KERN_DEBUG "in_dev_finish_destroy: %p=%s\n", idev, dev ? dev->name : "NIL"); 00112 #endif 00113 dev_put(dev); 00114 if (!idev->dead) { 00115 printk("Freeing alive in_device %p\n", idev); 00116 return; 00117 } 00118 inet_dev_count--; 00119 kfree(idev); 00120 }

__inline__ struct in_device* in_dev_get const struct net_device dev  )  [static]
 

Definition at line 134 of file inetdevice.h.

References inetdev_lock, and net_device::ip_ptr.

Referenced by arp_constructor(), arp_fwd_proxy(), arp_process(), icmp_address_reply(), inetdev_by_index(), ip_mc_procinfo(), ip_mcf_procinfo(), ip_rcv_finish(), ip_route_input_mc(), ip_route_input_slow(), ip_route_output_slow(), ip_rt_redirect(), and ip_rt_send_redirect().

00135 { 00136 struct in_device *in_dev; 00137 00138 read_lock(&inetdev_lock); 00139 in_dev = dev->ip_ptr; 00140 if (in_dev) 00141 atomic_inc(&in_dev->refcnt); 00142 read_unlock(&inetdev_lock); 00143 return in_dev; 00144 }

__inline__ void in_dev_put struct in_device idev  )  [static]
 

Definition at line 155 of file inetdevice.h.

References in_dev_finish_destroy(), and in_device::refcnt.

Referenced by arp_constructor(), arp_fwd_proxy(), arp_process(), fib_check_nh(), icmp_address_reply(), inetdev_destroy(), ip_ma_put(), ip_mc_drop_socket(), ip_mc_leave_group(), ip_mc_procinfo(), ip_mcf_procinfo(), ip_rcv_finish(), ip_route_input_mc(), ip_route_input_slow(), ip_route_output_slow(), ip_rt_redirect(), and ip_rt_send_redirect().

00156 { 00157 if (atomic_dec_and_test(&idev->refcnt)) 00158 in_dev_finish_destroy(idev); 00159 }

int inet_addr_onlink struct in_device in_dev,
u32  a,
u32  b
 

Definition at line 187 of file devinet.c.

References endfor_ifa, for_primary_ifa, inet_ifa_match(), and in_device::lock.

Referenced by ip_route_input_slow(), and ip_rt_redirect().

00188 { 00189 read_lock(&in_dev->lock); 00190 for_primary_ifa(in_dev) { 00191 if (inet_ifa_match(a, ifa)) { 00192 if (!b || inet_ifa_match(b, ifa)) { 00193 read_unlock(&in_dev->lock); 00194 return 1; 00195 } 00196 } 00197 } endfor_ifa(in_dev); 00198 read_unlock(&in_dev->lock); 00199 return 0; 00200 }

void inet_forward_change void   ) 
 

struct in_ifaddr* inet_ifa_byprefix struct in_device in_dev,
u32  prefix,
u32  mask
 

Definition at line 347 of file devinet.c.

References endfor_ifa, for_primary_ifa, and inet_ifa_match().

Referenced by fib_add_ifaddr(), and fib_del_ifaddr().

00348 { 00349 ASSERT_RTNL(); 00350 00351 for_primary_ifa(in_dev) { 00352 if (ifa->ifa_mask == mask && inet_ifa_match(prefix, ifa)) 00353 return ifa; 00354 } endfor_ifa(in_dev); 00355 return NULL; 00356 }

__inline__ int inet_ifa_match u32  addr,
struct in_ifaddr ifa
[static]
 

Definition at line 102 of file inetdevice.h.

References in_ifaddr::ifa_address, and in_ifaddr::ifa_mask.

Referenced by icmp_address_reply(), inet_addr_onlink(), inet_del_ifa(), inet_ifa_byprefix(), inet_insert_ifa(), inet_rtm_deladdr(), and inet_select_addr().

00103 { 00104 return !((addr^ifa->ifa_address)&ifa->ifa_mask); 00105 }

__inline__ __u32 inet_make_mask int  logmask  )  [static]
 

Definition at line 166 of file inetdevice.h.

Referenced by devinet_ioctl(), fib_rules_map_destination(), fn_new_zone(), inet_rtm_newaddr(), inet_rtm_newrule(), and inetdev_event().

00167 { 00168 if (logmask) 00169 return htonl(~((1<<(32-logmask))-1)); 00170 return 0; 00171 }

__inline__ int inet_mask_len __u32  mask  )  [static]
 

Definition at line 173 of file inetdevice.h.

Referenced by devinet_ioctl(), and fib_convert_rtentry().

00174 { 00175 if (!(mask = ntohl(mask))) 00176 return 0; 00177 return 32 - ffz(~mask); 00178 }

u32 inet_select_addr const struct net_device dev,
u32  dst,
int  scope
 

Definition at line 718 of file devinet.c.

References __in_dev_get(), dev_base, dev_base_lock, endfor_ifa, for_primary_ifa, inet_ifa_match(), inetdev_lock, net_device::next, and scope.

Referenced by __fib_res_prefsrc(), arp_solicit(), bind_mcastif_addr(), do_masquerade(), fib_validate_source(), ip_route_input_mc(), ip_route_input_slow(), ip_route_output_slow(), and ip_rt_get_source().

00719 { 00720 u32 addr = 0; 00721 struct in_device *in_dev; 00722 00723 read_lock(&inetdev_lock); 00724 in_dev = __in_dev_get(dev); 00725 if (in_dev == NULL) { 00726 read_unlock(&inetdev_lock); 00727 return 0; 00728 } 00729 00730 read_lock(&in_dev->lock); 00731 for_primary_ifa(in_dev) { 00732 if (ifa->ifa_scope > scope) 00733 continue; 00734 if (!dst || inet_ifa_match(dst, ifa)) { 00735 addr = ifa->ifa_local; 00736 break; 00737 } 00738 if (!addr) 00739 addr = ifa->ifa_local; 00740 } endfor_ifa(in_dev); 00741 read_unlock(&in_dev->lock); 00742 read_unlock(&inetdev_lock); 00743 00744 if (addr) 00745 return addr; 00746 00747 /* Not loopback addresses on loopback should be preferred 00748 in this case. It is importnat that lo is the first interface 00749 in dev_base list. 00750 */ 00751 read_lock(&dev_base_lock); 00752 read_lock(&inetdev_lock); 00753 for (dev=dev_base; dev; dev=dev->next) { 00754 if ((in_dev=__in_dev_get(dev)) == NULL) 00755 continue; 00756 00757 read_lock(&in_dev->lock); 00758 for_primary_ifa(in_dev) { 00759 if (ifa->ifa_scope != RT_SCOPE_LINK && 00760 ifa->ifa_scope <= scope) { 00761 read_unlock(&in_dev->lock); 00762 read_unlock(&inetdev_lock); 00763 read_unlock(&dev_base_lock); 00764 return ifa->ifa_local; 00765 } 00766 } endfor_ifa(in_dev); 00767 read_unlock(&in_dev->lock); 00768 } 00769 read_unlock(&inetdev_lock); 00770 read_unlock(&dev_base_lock); 00771 00772 return 0; 00773 }

struct in_device* inetdev_by_index int   ) 
 

Definition at line 333 of file devinet.c.

References __dev_get_by_index(), dev_base_lock, and in_dev_get().

Referenced by fib_check_nh(), inet_rtm_deladdr(), ip_mc_drop_socket(), ip_mc_find_dev(), and ip_mc_leave_group().

00334 { 00335 struct net_device *dev; 00336 struct in_device *in_dev = NULL; 00337 read_lock(&dev_base_lock); 00338 dev = __dev_get_by_index(ifindex); 00339 if (dev) 00340 in_dev = in_dev_get(dev); 00341 read_unlock(&dev_base_lock); 00342 return in_dev; 00343 }

struct in_device* inetdev_init struct net_device dev  ) 
 

Definition at line 122 of file devinet.c.

References arp_tbl, dev_hold, net_device::flags, in_dev_hold, inet_dev_count, inetdev_lock, ip_mc_up(), net_device::ip_ptr, ipv4_devconf_dflt, neigh_parms_alloc(), and neigh_sysctl_register().

Referenced by inet_rtm_newaddr(), inet_set_ifa(), and ipmr_new_tunnel().

00123 { 00124 struct in_device *in_dev; 00125 00126 ASSERT_RTNL(); 00127 00128 in_dev = kmalloc(sizeof(*in_dev), GFP_KERNEL); 00129 if (!in_dev) 00130 return NULL; 00131 memset(in_dev, 0, sizeof(*in_dev)); 00132 in_dev->lock = RW_LOCK_UNLOCKED; 00133 memcpy(&in_dev->cnf, &ipv4_devconf_dflt, sizeof(in_dev->cnf)); 00134 in_dev->cnf.sysctl = NULL; 00135 in_dev->dev = dev; 00136 if ((in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl)) == NULL) { 00137 kfree(in_dev); 00138 return NULL; 00139 } 00140 inet_dev_count++; 00141 /* Reference in_dev->dev */ 00142 dev_hold(dev); 00143 #ifdef CONFIG_SYSCTL 00144 neigh_sysctl_register(dev, in_dev->arp_parms, NET_IPV4, NET_IPV4_NEIGH, "ipv4"); 00145 #endif 00146 write_lock_bh(&inetdev_lock); 00147 dev->ip_ptr = in_dev; 00148 /* Account for reference dev->ip_ptr */ 00149 in_dev_hold(in_dev); 00150 write_unlock_bh(&inetdev_lock); 00151 #ifdef CONFIG_SYSCTL 00152 devinet_sysctl_register(in_dev, &in_dev->cnf); 00153 #endif 00154 if (dev->flags&IFF_UP) 00155 ip_mc_up(in_dev); 00156 return in_dev; 00157 }

struct net_device* ip_dev_find u32  addr  ) 
 

Definition at line 145 of file fib_frontend.c.

References dev_hold, FIB_RES_DEV, fib_res_put(), local_table, fib_table::tb_lookup, and fib_result::type.

Referenced by ip_mc_find_dev(), ip_route_output_slow(), ip_setsockopt(), and vif_add().

00146 { 00147 struct rt_key key; 00148 struct fib_result res; 00149 struct net_device *dev = NULL; 00150 00151 memset(&key, 0, sizeof(key)); 00152 key.dst = addr; 00153 #ifdef CONFIG_IP_MULTIPLE_TABLES 00154 res.r = NULL; 00155 #endif 00156 00157 if (!local_table || local_table->tb_lookup(local_table, &key, &res)) { 00158 return NULL; 00159 } 00160 if (res.type != RTN_LOCAL) 00161 goto out; 00162 dev = FIB_RES_DEV(res); 00163 00164 if (dev) 00165 dev_hold(dev); 00166 out: 00167 fib_res_put(&res); 00168 return dev; 00169 }

int register_inetaddr_notifier struct notifier_block *  nb  ) 
 

Definition at line 779 of file devinet.c.

References inetaddr_chain.

Referenced by init(), and ip_fib_init().

00780 { 00781 return notifier_chain_register(&inetaddr_chain, nb); 00782 }

int unregister_inetaddr_notifier struct notifier_block *  nb  ) 
 

Definition at line 784 of file devinet.c.

References inetaddr_chain.

Referenced by fini().

00785 { 00786 return notifier_chain_unregister(&inetaddr_chain,nb); 00787 }


Variable Documentation

rwlock_t inetdev_lock
 

Definition at line 80 of file devinet.c.

Referenced by fib_validate_source(), in_dev_get(), inet_dump_ifaddr(), inet_select_addr(), inetdev_destroy(), inetdev_init(), ip_route_input(), and ip_route_output_slow().

struct ipv4_devconf ipv4_devconf
 

Definition at line 63 of file devinet.c.


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