aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/ipconfig.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2006-11-08 03:19:38 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-03 00:21:09 -0500
commit5a874db4d9bfd8a4c6324d844a4d1c7cfa5cf2c4 (patch)
tree7e3451c3931a8c4124ca040a86e20fe8ba8c71aa /net/ipv4/ipconfig.c
parent3e6c8cd5669c1202fe806ce3e13d701f20a71c7e (diff)
[NET]: ipconfig and nfsroot annotations
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/ipconfig.c')
-rw-r--r--net/ipv4/ipconfig.c105
1 files changed, 53 insertions, 52 deletions
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 955a07abb91d..afa60b9a003f 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -101,6 +101,7 @@
101#define CONF_NAMESERVERS_MAX 3 /* Maximum number of nameservers 101#define CONF_NAMESERVERS_MAX 3 /* Maximum number of nameservers
102 - '3' from resolv.h */ 102 - '3' from resolv.h */
103 103
104#define NONE __constant_htonl(INADDR_NONE)
104 105
105/* 106/*
106 * Public IP configuration 107 * Public IP configuration
@@ -129,19 +130,19 @@ int ic_proto_enabled __initdata = 0
129 130
130static int ic_host_name_set __initdata = 0; /* Host name set by us? */ 131static int ic_host_name_set __initdata = 0; /* Host name set by us? */
131 132
132u32 ic_myaddr = INADDR_NONE; /* My IP address */ 133__be32 ic_myaddr = NONE; /* My IP address */
133static u32 ic_netmask = INADDR_NONE; /* Netmask for local subnet */ 134static __be32 ic_netmask = NONE; /* Netmask for local subnet */
134u32 ic_gateway = INADDR_NONE; /* Gateway IP address */ 135__be32 ic_gateway = NONE; /* Gateway IP address */
135 136
136u32 ic_servaddr = INADDR_NONE; /* Boot server IP address */ 137__be32 ic_servaddr = NONE; /* Boot server IP address */
137 138
138u32 root_server_addr = INADDR_NONE; /* Address of NFS server */ 139__be32 root_server_addr = NONE; /* Address of NFS server */
139u8 root_server_path[256] = { 0, }; /* Path to mount as root */ 140u8 root_server_path[256] = { 0, }; /* Path to mount as root */
140 141
141/* Persistent data: */ 142/* Persistent data: */
142 143
143static int ic_proto_used; /* Protocol used, if any */ 144static int ic_proto_used; /* Protocol used, if any */
144static u32 ic_nameservers[CONF_NAMESERVERS_MAX]; /* DNS Server IP addresses */ 145static __be32 ic_nameservers[CONF_NAMESERVERS_MAX]; /* DNS Server IP addresses */
145static u8 ic_domain[64]; /* DNS (not NIS) domain name */ 146static u8 ic_domain[64]; /* DNS (not NIS) domain name */
146 147
147/* 148/*
@@ -172,7 +173,7 @@ struct ic_device {
172 struct net_device *dev; 173 struct net_device *dev;
173 unsigned short flags; 174 unsigned short flags;
174 short able; 175 short able;
175 u32 xid; 176 __be32 xid;
176}; 177};
177 178
178static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */ 179static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */
@@ -223,7 +224,7 @@ static int __init ic_open_devs(void)
223 d->flags = oflags; 224 d->flags = oflags;
224 d->able = able; 225 d->able = able;
225 if (able & IC_BOOTP) 226 if (able & IC_BOOTP)
226 get_random_bytes(&d->xid, sizeof(u32)); 227 get_random_bytes(&d->xid, sizeof(__be32));
227 else 228 else
228 d->xid = 0; 229 d->xid = 0;
229 ic_proto_have_if |= able; 230 ic_proto_have_if |= able;
@@ -269,7 +270,7 @@ static void __init ic_close_devs(void)
269 */ 270 */
270 271
271static inline void 272static inline void
272set_sockaddr(struct sockaddr_in *sin, u32 addr, u16 port) 273set_sockaddr(struct sockaddr_in *sin, __be32 addr, __be16 port)
273{ 274{
274 sin->sin_family = AF_INET; 275 sin->sin_family = AF_INET;
275 sin->sin_addr.s_addr = addr; 276 sin->sin_addr.s_addr = addr;
@@ -332,7 +333,7 @@ static int __init ic_setup_routes(void)
332{ 333{
333 /* No need to setup device routes, only the default route... */ 334 /* No need to setup device routes, only the default route... */
334 335
335 if (ic_gateway != INADDR_NONE) { 336 if (ic_gateway != NONE) {
336 struct rtentry rm; 337 struct rtentry rm;
337 int err; 338 int err;
338 339
@@ -368,10 +369,10 @@ static int __init ic_defaults(void)
368 if (!ic_host_name_set) 369 if (!ic_host_name_set)
369 sprintf(init_utsname()->nodename, "%u.%u.%u.%u", NIPQUAD(ic_myaddr)); 370 sprintf(init_utsname()->nodename, "%u.%u.%u.%u", NIPQUAD(ic_myaddr));
370 371
371 if (root_server_addr == INADDR_NONE) 372 if (root_server_addr == NONE)
372 root_server_addr = ic_servaddr; 373 root_server_addr = ic_servaddr;
373 374
374 if (ic_netmask == INADDR_NONE) { 375 if (ic_netmask == NONE) {
375 if (IN_CLASSA(ntohl(ic_myaddr))) 376 if (IN_CLASSA(ntohl(ic_myaddr)))
376 ic_netmask = htonl(IN_CLASSA_NET); 377 ic_netmask = htonl(IN_CLASSA_NET);
377 else if (IN_CLASSB(ntohl(ic_myaddr))) 378 else if (IN_CLASSB(ntohl(ic_myaddr)))
@@ -420,7 +421,7 @@ ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
420{ 421{
421 struct arphdr *rarp; 422 struct arphdr *rarp;
422 unsigned char *rarp_ptr; 423 unsigned char *rarp_ptr;
423 u32 sip, tip; 424 __be32 sip, tip;
424 unsigned char *sha, *tha; /* s for "source", t for "target" */ 425 unsigned char *sha, *tha; /* s for "source", t for "target" */
425 struct ic_device *d; 426 struct ic_device *d;
426 427
@@ -485,12 +486,12 @@ ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
485 goto drop_unlock; 486 goto drop_unlock;
486 487
487 /* Discard packets which are not from specified server. */ 488 /* Discard packets which are not from specified server. */
488 if (ic_servaddr != INADDR_NONE && ic_servaddr != sip) 489 if (ic_servaddr != NONE && ic_servaddr != sip)
489 goto drop_unlock; 490 goto drop_unlock;
490 491
491 /* We have a winner! */ 492 /* We have a winner! */
492 ic_dev = dev; 493 ic_dev = dev;
493 if (ic_myaddr == INADDR_NONE) 494 if (ic_myaddr == NONE)
494 ic_myaddr = tip; 495 ic_myaddr = tip;
495 ic_servaddr = sip; 496 ic_servaddr = sip;
496 ic_got_reply = IC_RARP; 497 ic_got_reply = IC_RARP;
@@ -530,13 +531,13 @@ struct bootp_pkt { /* BOOTP packet format */
530 u8 htype; /* HW address type */ 531 u8 htype; /* HW address type */
531 u8 hlen; /* HW address length */ 532 u8 hlen; /* HW address length */
532 u8 hops; /* Used only by gateways */ 533 u8 hops; /* Used only by gateways */
533 u32 xid; /* Transaction ID */ 534 __be32 xid; /* Transaction ID */
534 u16 secs; /* Seconds since we started */ 535 __be16 secs; /* Seconds since we started */
535 u16 flags; /* Just what it says */ 536 __be16 flags; /* Just what it says */
536 u32 client_ip; /* Client's IP address if known */ 537 __be32 client_ip; /* Client's IP address if known */
537 u32 your_ip; /* Assigned IP address */ 538 __be32 your_ip; /* Assigned IP address */
538 u32 server_ip; /* (Next, e.g. NFS) Server's IP address */ 539 __be32 server_ip; /* (Next, e.g. NFS) Server's IP address */
539 u32 relay_ip; /* IP address of BOOTP relay */ 540 __be32 relay_ip; /* IP address of BOOTP relay */
540 u8 hw_addr[16]; /* Client's HW address */ 541 u8 hw_addr[16]; /* Client's HW address */
541 u8 serv_name[64]; /* Server host name */ 542 u8 serv_name[64]; /* Server host name */
542 u8 boot_file[128]; /* Name of boot file */ 543 u8 boot_file[128]; /* Name of boot file */
@@ -576,7 +577,7 @@ static const u8 ic_bootp_cookie[4] = { 99, 130, 83, 99 };
576static void __init 577static void __init
577ic_dhcp_init_options(u8 *options) 578ic_dhcp_init_options(u8 *options)
578{ 579{
579 u8 mt = ((ic_servaddr == INADDR_NONE) 580 u8 mt = ((ic_servaddr == NONE)
580 ? DHCPDISCOVER : DHCPREQUEST); 581 ? DHCPDISCOVER : DHCPREQUEST);
581 u8 *e = options; 582 u8 *e = options;
582 583
@@ -666,7 +667,7 @@ static inline void ic_bootp_init(void)
666 int i; 667 int i;
667 668
668 for (i = 0; i < CONF_NAMESERVERS_MAX; i++) 669 for (i = 0; i < CONF_NAMESERVERS_MAX; i++)
669 ic_nameservers[i] = INADDR_NONE; 670 ic_nameservers[i] = NONE;
670 671
671 dev_add_pack(&bootp_packet_type); 672 dev_add_pack(&bootp_packet_type);
672} 673}
@@ -708,7 +709,7 @@ static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_d
708 h->frag_off = htons(IP_DF); 709 h->frag_off = htons(IP_DF);
709 h->ttl = 64; 710 h->ttl = 64;
710 h->protocol = IPPROTO_UDP; 711 h->protocol = IPPROTO_UDP;
711 h->daddr = INADDR_BROADCAST; 712 h->daddr = htonl(INADDR_BROADCAST);
712 h->check = ip_fast_csum((unsigned char *) h, h->ihl); 713 h->check = ip_fast_csum((unsigned char *) h, h->ihl);
713 714
714 /* Construct UDP header */ 715 /* Construct UDP header */
@@ -730,8 +731,8 @@ static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_d
730 b->htype = dev->type; /* can cause undefined behavior */ 731 b->htype = dev->type; /* can cause undefined behavior */
731 } 732 }
732 b->hlen = dev->addr_len; 733 b->hlen = dev->addr_len;
733 b->your_ip = INADDR_NONE; 734 b->your_ip = NONE;
734 b->server_ip = INADDR_NONE; 735 b->server_ip = NONE;
735 memcpy(b->hw_addr, dev->dev_addr, dev->addr_len); 736 memcpy(b->hw_addr, dev->dev_addr, dev->addr_len);
736 b->secs = htons(jiffies_diff / HZ); 737 b->secs = htons(jiffies_diff / HZ);
737 b->xid = d->xid; 738 b->xid = d->xid;
@@ -788,11 +789,11 @@ static void __init ic_do_bootp_ext(u8 *ext)
788 789
789 switch (*ext++) { 790 switch (*ext++) {
790 case 1: /* Subnet mask */ 791 case 1: /* Subnet mask */
791 if (ic_netmask == INADDR_NONE) 792 if (ic_netmask == NONE)
792 memcpy(&ic_netmask, ext+1, 4); 793 memcpy(&ic_netmask, ext+1, 4);
793 break; 794 break;
794 case 3: /* Default gateway */ 795 case 3: /* Default gateway */
795 if (ic_gateway == INADDR_NONE) 796 if (ic_gateway == NONE)
796 memcpy(&ic_gateway, ext+1, 4); 797 memcpy(&ic_gateway, ext+1, 4);
797 break; 798 break;
798 case 6: /* DNS server */ 799 case 6: /* DNS server */
@@ -800,7 +801,7 @@ static void __init ic_do_bootp_ext(u8 *ext)
800 if (servers > CONF_NAMESERVERS_MAX) 801 if (servers > CONF_NAMESERVERS_MAX)
801 servers = CONF_NAMESERVERS_MAX; 802 servers = CONF_NAMESERVERS_MAX;
802 for (i = 0; i < servers; i++) { 803 for (i = 0; i < servers; i++) {
803 if (ic_nameservers[i] == INADDR_NONE) 804 if (ic_nameservers[i] == NONE)
804 memcpy(&ic_nameservers[i], ext+1+4*i, 4); 805 memcpy(&ic_nameservers[i], ext+1+4*i, 4);
805 } 806 }
806 break; 807 break;
@@ -917,7 +918,7 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
917 918
918#ifdef IPCONFIG_DHCP 919#ifdef IPCONFIG_DHCP
919 if (ic_proto_enabled & IC_USE_DHCP) { 920 if (ic_proto_enabled & IC_USE_DHCP) {
920 u32 server_id = INADDR_NONE; 921 __be32 server_id = NONE;
921 int mt = 0; 922 int mt = 0;
922 923
923 ext = &b->exten[4]; 924 ext = &b->exten[4];
@@ -949,7 +950,7 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
949 /* While in the process of accepting one offer, 950 /* While in the process of accepting one offer,
950 * ignore all others. 951 * ignore all others.
951 */ 952 */
952 if (ic_myaddr != INADDR_NONE) 953 if (ic_myaddr != NONE)
953 goto drop_unlock; 954 goto drop_unlock;
954 955
955 /* Let's accept that offer. */ 956 /* Let's accept that offer. */
@@ -965,7 +966,7 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
965 * precedence over the bootp header one if 966 * precedence over the bootp header one if
966 * they are different. 967 * they are different.
967 */ 968 */
968 if ((server_id != INADDR_NONE) && 969 if ((server_id != NONE) &&
969 (b->server_ip != server_id)) 970 (b->server_ip != server_id))
970 b->server_ip = ic_servaddr; 971 b->server_ip = ic_servaddr;
971 break; 972 break;
@@ -979,8 +980,8 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
979 980
980 default: 981 default:
981 /* Urque. Forget it*/ 982 /* Urque. Forget it*/
982 ic_myaddr = INADDR_NONE; 983 ic_myaddr = NONE;
983 ic_servaddr = INADDR_NONE; 984 ic_servaddr = NONE;
984 goto drop_unlock; 985 goto drop_unlock;
985 }; 986 };
986 987
@@ -1004,9 +1005,9 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
1004 ic_dev = dev; 1005 ic_dev = dev;
1005 ic_myaddr = b->your_ip; 1006 ic_myaddr = b->your_ip;
1006 ic_servaddr = b->server_ip; 1007 ic_servaddr = b->server_ip;
1007 if (ic_gateway == INADDR_NONE && b->relay_ip) 1008 if (ic_gateway == NONE && b->relay_ip)
1008 ic_gateway = b->relay_ip; 1009 ic_gateway = b->relay_ip;
1009 if (ic_nameservers[0] == INADDR_NONE) 1010 if (ic_nameservers[0] == NONE)
1010 ic_nameservers[0] = ic_servaddr; 1011 ic_nameservers[0] = ic_servaddr;
1011 ic_got_reply = IC_BOOTP; 1012 ic_got_reply = IC_BOOTP;
1012 1013
@@ -1150,7 +1151,7 @@ static int __init ic_dynamic(void)
1150#endif 1151#endif
1151 1152
1152 if (!ic_got_reply) { 1153 if (!ic_got_reply) {
1153 ic_myaddr = INADDR_NONE; 1154 ic_myaddr = NONE;
1154 return -1; 1155 return -1;
1155 } 1156 }
1156 1157
@@ -1182,12 +1183,12 @@ static int pnp_seq_show(struct seq_file *seq, void *v)
1182 seq_printf(seq, 1183 seq_printf(seq,
1183 "domain %s\n", ic_domain); 1184 "domain %s\n", ic_domain);
1184 for (i = 0; i < CONF_NAMESERVERS_MAX; i++) { 1185 for (i = 0; i < CONF_NAMESERVERS_MAX; i++) {
1185 if (ic_nameservers[i] != INADDR_NONE) 1186 if (ic_nameservers[i] != NONE)
1186 seq_printf(seq, 1187 seq_printf(seq,
1187 "nameserver %u.%u.%u.%u\n", 1188 "nameserver %u.%u.%u.%u\n",
1188 NIPQUAD(ic_nameservers[i])); 1189 NIPQUAD(ic_nameservers[i]));
1189 } 1190 }
1190 if (ic_servaddr != INADDR_NONE) 1191 if (ic_servaddr != NONE)
1191 seq_printf(seq, 1192 seq_printf(seq,
1192 "bootserver %u.%u.%u.%u\n", 1193 "bootserver %u.%u.%u.%u\n",
1193 NIPQUAD(ic_servaddr)); 1194 NIPQUAD(ic_servaddr));
@@ -1213,9 +1214,9 @@ static struct file_operations pnp_seq_fops = {
1213 * need to have root_server_addr set _before_ IPConfig gets called as it 1214 * need to have root_server_addr set _before_ IPConfig gets called as it
1214 * can override it. 1215 * can override it.
1215 */ 1216 */
1216u32 __init root_nfs_parse_addr(char *name) 1217__be32 __init root_nfs_parse_addr(char *name)
1217{ 1218{
1218 u32 addr; 1219 __be32 addr;
1219 int octets = 0; 1220 int octets = 0;
1220 char *cp, *cq; 1221 char *cp, *cq;
1221 1222
@@ -1237,7 +1238,7 @@ u32 __init root_nfs_parse_addr(char *name)
1237 addr = in_aton(name); 1238 addr = in_aton(name);
1238 memmove(name, cp, strlen(cp) + 1); 1239 memmove(name, cp, strlen(cp) + 1);
1239 } else 1240 } else
1240 addr = INADDR_NONE; 1241 addr = NONE;
1241 1242
1242 return addr; 1243 return addr;
1243} 1244}
@@ -1248,7 +1249,7 @@ u32 __init root_nfs_parse_addr(char *name)
1248 1249
1249static int __init ip_auto_config(void) 1250static int __init ip_auto_config(void)
1250{ 1251{
1251 u32 addr; 1252 __be32 addr;
1252 1253
1253#ifdef CONFIG_PROC_FS 1254#ifdef CONFIG_PROC_FS
1254 proc_net_fops_create("pnp", S_IRUGO, &pnp_seq_fops); 1255 proc_net_fops_create("pnp", S_IRUGO, &pnp_seq_fops);
@@ -1277,11 +1278,11 @@ static int __init ip_auto_config(void)
1277 * interfaces and no default was set), use BOOTP or RARP to get the 1278 * interfaces and no default was set), use BOOTP or RARP to get the
1278 * missing values. 1279 * missing values.
1279 */ 1280 */
1280 if (ic_myaddr == INADDR_NONE || 1281 if (ic_myaddr == NONE ||
1281#ifdef CONFIG_ROOT_NFS 1282#ifdef CONFIG_ROOT_NFS
1282 (MAJOR(ROOT_DEV) == UNNAMED_MAJOR 1283 (MAJOR(ROOT_DEV) == UNNAMED_MAJOR
1283 && root_server_addr == INADDR_NONE 1284 && root_server_addr == NONE
1284 && ic_servaddr == INADDR_NONE) || 1285 && ic_servaddr == NONE) ||
1285#endif 1286#endif
1286 ic_first_dev->next) { 1287 ic_first_dev->next) {
1287#ifdef IPCONFIG_DYNAMIC 1288#ifdef IPCONFIG_DYNAMIC
@@ -1334,7 +1335,7 @@ static int __init ip_auto_config(void)
1334 } 1335 }
1335 1336
1336 addr = root_nfs_parse_addr(root_server_path); 1337 addr = root_nfs_parse_addr(root_server_path);
1337 if (root_server_addr == INADDR_NONE) 1338 if (root_server_addr == NONE)
1338 root_server_addr = addr; 1339 root_server_addr = addr;
1339 1340
1340 /* 1341 /*
@@ -1461,19 +1462,19 @@ static int __init ip_auto_config_setup(char *addrs)
1461 switch (num) { 1462 switch (num) {
1462 case 0: 1463 case 0:
1463 if ((ic_myaddr = in_aton(ip)) == INADDR_ANY) 1464 if ((ic_myaddr = in_aton(ip)) == INADDR_ANY)
1464 ic_myaddr = INADDR_NONE; 1465 ic_myaddr = NONE;
1465 break; 1466 break;
1466 case 1: 1467 case 1:
1467 if ((ic_servaddr = in_aton(ip)) == INADDR_ANY) 1468 if ((ic_servaddr = in_aton(ip)) == INADDR_ANY)
1468 ic_servaddr = INADDR_NONE; 1469 ic_servaddr = NONE;
1469 break; 1470 break;
1470 case 2: 1471 case 2:
1471 if ((ic_gateway = in_aton(ip)) == INADDR_ANY) 1472 if ((ic_gateway = in_aton(ip)) == INADDR_ANY)
1472 ic_gateway = INADDR_NONE; 1473 ic_gateway = NONE;
1473 break; 1474 break;
1474 case 3: 1475 case 3:
1475 if ((ic_netmask = in_aton(ip)) == INADDR_ANY) 1476 if ((ic_netmask = in_aton(ip)) == INADDR_ANY)
1476 ic_netmask = INADDR_NONE; 1477 ic_netmask = NONE;
1477 break; 1478 break;
1478 case 4: 1479 case 4:
1479 if ((dp = strchr(ip, '.'))) { 1480 if ((dp = strchr(ip, '.'))) {