aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/udhcp/Config.in9
-rw-r--r--networking/udhcp/options.c7
-rw-r--r--networking/udhcp/options.h3
-rw-r--r--networking/udhcp/script.c44
4 files changed, 62 insertions, 1 deletions
diff --git a/networking/udhcp/Config.in b/networking/udhcp/Config.in
index 5baaa6a49..674470a39 100644
--- a/networking/udhcp/Config.in
+++ b/networking/udhcp/Config.in
@@ -38,5 +38,14 @@ config CONFIG_FEATURE_UDHCP_DEBUG
38 help 38 help
39 Please submit a patch to add help text for this item. 39 Please submit a patch to add help text for this item.
40 40
41config CONFIG_FEATURE_UDHCPC_IP
42 bool " Compile udhcpc with ip support"
43 default n
44 depends on CONFIG_UDHCPC
45 help
46 Say yes if you are using the ip command instead of route and ifconfig
47 in your scripts to bring up the interface.
48 This is needed as ip wants the subnet as a bitprefix not an ip value.
49
41endmenu 50endmenu
42 51
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 58144728e..3f3a38963 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -13,11 +13,16 @@
13#include "options.h" 13#include "options.h"
14#include "leases.h" 14#include "leases.h"
15 15
16#include "config.h"
16 17
17/* supported options are easily added here */ 18/* supported options are easily added here */
18struct dhcp_option options[] = { 19struct dhcp_option options[] = {
19 /* name[10] flags code */ 20 /* name[10] flags code */
20 {"subnet", OPTION_IP | OPTION_REQ, 0x01}, 21#ifdef CONFIG_FEATURE_UDHCPC_IP
22 {"subnet", OPTION_IP | OPTION_REQ | OPTION_PREFIX, 0x01},
23#else
24 {"subnet", OPTION_IP | OPTION_REQ, 0x01},
25#endif
21 {"timezone", OPTION_S32, 0x02}, 26 {"timezone", OPTION_S32, 0x02},
22 {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03}, 27 {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03},
23 {"timesvr", OPTION_IP | OPTION_LIST, 0x04}, 28 {"timesvr", OPTION_IP | OPTION_LIST, 0x04},
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index 1fded2ef4..dccaa2af9 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -4,6 +4,8 @@
4 4
5#include "packet.h" 5#include "packet.h"
6 6
7#include "config.h"
8
7#define TYPE_MASK 0x0F 9#define TYPE_MASK 0x0F
8 10
9enum { 11enum {
@@ -20,6 +22,7 @@ enum {
20 22
21#define OPTION_REQ 0x10 /* have the client request this option */ 23#define OPTION_REQ 0x10 /* have the client request this option */
22#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */ 24#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */
25#define OPTION_PREFIX 0x40 /* ip wants a prefix instead of a ip for subnet */
23 26
24struct dhcp_option { 27struct dhcp_option {
25 char name[10]; 28 char name[10];
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 4ce23aafc..1c6f1bd33 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -37,6 +37,8 @@
37#include "options.h" 37#include "options.h"
38#include "debug.h" 38#include "debug.h"
39 39
40#include "config.h"
41
40/* get a rough idea of how long an option will be (rounding up...) */ 42/* get a rough idea of how long an option will be (rounding up...) */
41static int max_option_length[] = { 43static int max_option_length[] = {
42 [OPTION_IP] = sizeof("255.255.255.255 "), 44 [OPTION_IP] = sizeof("255.255.255.255 "),
@@ -62,6 +64,37 @@ static int sprintip(char *dest, char *pre, unsigned char *ip) {
62 return sprintf(dest, "%s%d.%d.%d.%d ", pre, ip[0], ip[1], ip[2], ip[3]); 64 return sprintf(dest, "%s%d.%d.%d.%d ", pre, ip[0], ip[1], ip[2], ip[3]);
63} 65}
64 66
67#ifdef CONFIG_FEATURE_UDHCPC_IP
68/* convert a netmask (255.255.255.0) into the length (24) */
69static int inet_ntom (const char *src, short *dst)
70{
71 in_addr_t mask, num;
72
73 mask = ntohl(*(unsigned int *)src);
74
75 for (num = mask; num & 1; num >>= 1);
76
77 if (num != 0 && mask != 0)
78 {
79 for (num = ~mask; num & 1; num >>= 1);
80 if (num)
81 return 0;
82 }
83
84 for (num = 0; mask; mask <<= 1)
85 num++;
86
87 *dst = num;
88
89 return 1;
90}
91
92static int sprintprefix(char *dest, char *pre, unsigned char *ip) {
93 short sdest = 0;
94 inet_ntom(ip, &sdest);
95 return sprintf(dest, "%s%hd ", pre, sdest);
96}
97#endif
65 98
66/* Fill dest with the text of option 'option'. */ 99/* Fill dest with the text of option 'option'. */
67static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p) 100static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p)
@@ -84,9 +117,20 @@ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *
84 *(dest++) = '/'; 117 *(dest++) = '/';
85 option += 4; 118 option += 4;
86 optlen = 4; 119 optlen = 4;
120#ifndef CONFIG_FEATURE_UDHCPC_IP
87 case OPTION_IP: /* Works regardless of host byte order. */ 121 case OPTION_IP: /* Works regardless of host byte order. */
122#endif
88 dest += sprintip(dest, "", option); 123 dest += sprintip(dest, "", option);
89 break; 124 break;
125#ifdef CONFIG_FEATURE_UDHCPC_IP
126 case OPTION_IP: /* Works regardless of host byte order. */
127 if (type_p->flags & OPTION_PREFIX) {
128 dest += sprintprefix(dest, "", option);
129 } else {
130 dest += sprintip(dest, "", option);
131 }
132 break;
133#endif
90 case OPTION_BOOLEAN: 134 case OPTION_BOOLEAN:
91 dest += sprintf(dest, *option ? "yes " : "no "); 135 dest += sprintf(dest, *option ? "yes " : "no ");
92 break; 136 break;