summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko2010-03-20 18:06:23 +0100
committerDenys Vlasenko2010-03-20 18:06:23 +0100
commit87fa216e1e388c537cda2cff126eea816a4135ac (patch)
treebfbf5781bd9b33525029c162d59902ac438ea2a4 /networking
parent0f62c4d065bc7fa9d3de52a8482bf48ecfd18ecf (diff)
downloadbusybox-87fa216e1e388c537cda2cff126eea816a4135ac.zip
busybox-87fa216e1e388c537cda2cff126eea816a4135ac.tar.gz
udhcpc: make it possible to disable vendor id; improve help text
function old new delta init_packet 135 139 +4 packed_usage 26789 26786 -3 alloc_dhcp_option 67 63 -4 udhcpc_main 2467 2447 -20 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 4/-27) Total: -23 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/udhcp/clientpacket.c6
-rw-r--r--networking/udhcp/dhcpc.c49
-rw-r--r--networking/udhcp/options.c1
-rw-r--r--networking/udhcp/options.h12
4 files changed, 36 insertions, 32 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index f091d80..a255d6e 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -47,8 +47,12 @@ static void init_packet(struct dhcp_packet *packet, char type)
add_option_string(packet->options, client_config.hostname);
if (client_config.fqdn)
add_option_string(packet->options, client_config.fqdn);
- if ((type != DHCPDECLINE) && (type != DHCPRELEASE))
+ if (type != DHCPDECLINE
+ && type != DHCPRELEASE
+ && client_config.vendorclass
+ ) {
add_option_string(packet->options, client_config.vendorclass);
+ }
}
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 9a2fe35..3e2cd12 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -125,8 +125,7 @@ static void client_background(void)
static uint8_t* alloc_dhcp_option(int code, const char *str, int extra)
{
uint8_t *storage;
- int len = strlen(str);
- if (len > 255) len = 255;
+ int len = strnlen(str, 255);
storage = xzalloc(len + extra + OPT_DATA);
storage[OPT_CODE] = code;
storage[OPT_LEN] = len + extra;
@@ -139,7 +138,7 @@ int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int udhcpc_main(int argc UNUSED_PARAM, char **argv)
{
uint8_t *temp, *message;
- char *str_c, *str_V, *str_h, *str_F, *str_r;
+ const char *str_c, *str_V, *str_h, *str_F, *str_r;
IF_FEATURE_UDHCP_PORT(char *str_P;)
llist_t *list_O = NULL;
int tryagain_timeout = 20;
@@ -222,6 +221,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;)
client_config.interface = "eth0";
client_config.script = DEFAULT_SCRIPT;
+ str_V = "udhcp "BB_VER;
/* Parse command line */
/* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */
@@ -246,23 +246,22 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
, &dhcp_verbose
#endif
);
- if (opt & OPT_c)
- client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0);
- if (opt & OPT_V)
- client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
if (opt & (OPT_h|OPT_H))
client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
if (opt & OPT_F) {
+ /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */
client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);
- /* Flags: 0000NEOS
- S: 1 => Client requests Server to update A RR in DNS as well as PTR
- O: 1 => Server indicates to client that DNS has been updated regardless
- E: 1 => Name data is DNS format, i.e. <4>host<6>domain<3>com<0> not "host.domain.com"
- N: 1 => Client requests Server to not update DNS
- */
+ /* Flag bits: 0000NEOS
+ * S: 1 = Client requests server to update A RR in DNS as well as PTR
+ * O: 1 = Server indicates to client that DNS has been updated regardless
+ * E: 1 = Name is in DNS format, i.e. <4>host<6>domain<3>com<0>,
+ * not "host.domain.com". Format 0 is obsolete.
+ * N: 1 = Client requests server to not update DNS (S must be 0 then)
+ * Two [0] bytes which follow are deprecated and must be 0.
+ */
client_config.fqdn[OPT_DATA + 0] = 0x1;
- /* client_config.fqdn[OPT_DATA + 1] = 0; - redundant */
- /* client_config.fqdn[OPT_DATA + 2] = 0; - redundant */
+ /*client_config.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */
+ /*client_config.fqdn[OPT_DATA + 2] = 0; */
}
if (opt & OPT_r)
requested_ip = inet_addr(str_r);
@@ -291,6 +290,16 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
return 1;
}
+ if (opt & OPT_c) {
+ client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0);
+ } else if (!(opt & OPT_C)) {
+ /* not set and not suppressed, set the default client ID */
+ client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7);
+ client_config.clientid[OPT_DATA] = 1; /* type: ethernet */
+ memcpy(client_config.clientid + OPT_DATA+1, client_config.client_mac, 6);
+ }
+ if (str_V[0] != '\0')
+ client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
#if !BB_MMU
/* on NOMMU reexec (i.e., background) early */
if (!(opt & OPT_f)) {
@@ -314,16 +323,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* Goes to stdout (unless NOMMU) and possibly syslog */
bb_info_msg("%s (v"BB_VER") started", applet_name);
- /* If not set, and not suppressed, set up the default client ID */
- if (!client_config.clientid && !(opt & OPT_C)) {
- client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7);
- client_config.clientid[OPT_DATA] = 1;
- memcpy(client_config.clientid + OPT_DATA+1, client_config.client_mac, 6);
- }
-
- if (!client_config.vendorclass)
- client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, "udhcp "BB_VER, 0);
-
/* Set up the signal pipe */
udhcp_sp_setup();
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index c2a2305..09d31c69 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -13,6 +13,7 @@
/* Supported options are easily added here.
* See RFC2132 for more options.
+ * OPTION_REQ: these options are requested by udhcpc (unless -o).
*/
const struct dhcp_option dhcp_options[] = {
/* flags code */
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index 2d9c15f..75087fa 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -46,9 +46,9 @@ enum {
#define DHCP_LOG_SERVER 0x07
//#define DHCP_COOKIE_SERVER 0x08 /* "quote of the day" server */
#define DHCP_LPR_SERVER 0x09
-#define DHCP_HOST_NAME 0x0c
+#define DHCP_HOST_NAME 0x0c /* either client informs server or server gives name to client */
#define DHCP_BOOT_SIZE 0x0d
-#define DHCP_DOMAIN_NAME 0x0f
+#define DHCP_DOMAIN_NAME 0x0f /* server gives domain suffix */
#define DHCP_SWAP_SERVER 0x10
#define DHCP_ROOT_PATH 0x11
#define DHCP_IP_TTL 0x17
@@ -61,14 +61,14 @@ enum {
#define DHCP_OPTION_OVERLOAD 0x34
#define DHCP_MESSAGE_TYPE 0x35
#define DHCP_SERVER_ID 0x36 /* by default server's IP */
-#define DHCP_PARAM_REQ 0x37
+#define DHCP_PARAM_REQ 0x37 /* list of options client wants */
#define DHCP_MESSAGE 0x38 /* error message when sending NAK etc */
#define DHCP_MAX_SIZE 0x39
//#define DHCP_T1 0x3a
//#define DHCP_T2 0x3b
-#define DHCP_VENDOR 0x3c /* client's vendor */
-#define DHCP_CLIENT_ID 0x3d /* by default client's MAC addr */
-#define DHCP_FQDN 0x51
+#define DHCP_VENDOR 0x3c /* client's vendor (a string) */
+#define DHCP_CLIENT_ID 0x3d /* by default client's MAC addr, but may be arbitrarily long */
+#define DHCP_FQDN 0x51 /* client asks to update DNS to map its FQDN to its new IP */
#define DHCP_STATIC_ROUTES 0x79
#define DHCP_END 0xFF
/* Offsets in option byte sequence */