udhcpc: remove deprecated -H/-h HOSTNAME options (9 years), deprecate -V VENDOR

function                                             old     new   delta
udhcpc_main                                         2563    2582     +19
dhcp_option_strings                                  294     301      +7
dhcp_optflags                                         80      82      +2
.rodata                                           103250  103248      -2
udhcpc_longopts                                      252     241     -11
add_client_options                                   209     175     -34
alloc_dhcp_option                                     59       -     -59
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/3 up/down: 28/-106)           Total: -78 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-06-02 15:07:46 +02:00
parent 265fcddd08
commit 698cdef538
4 changed files with 36 additions and 50 deletions

View File

@ -49,6 +49,7 @@ const struct dhcp_optflag dhcp_optflags[] = {
{ OPTION_U32 , 0x33 }, /* DHCP_LEASE_TIME */ { OPTION_U32 , 0x33 }, /* DHCP_LEASE_TIME */
{ OPTION_IP , 0x36 }, /* DHCP_SERVER_ID */ { OPTION_IP , 0x36 }, /* DHCP_SERVER_ID */
{ OPTION_STRING , 0x38 }, /* DHCP_ERR_MESSAGE */ { OPTION_STRING , 0x38 }, /* DHCP_ERR_MESSAGE */
{ OPTION_STRING , 0x3c }, /* DHCP_VENDOR */
//TODO: must be combined with 'sname' and 'file' handling: //TODO: must be combined with 'sname' and 'file' handling:
{ OPTION_STRING_HOST , 0x42 }, /* DHCP_TFTP_SERVER_NAME */ { OPTION_STRING_HOST , 0x42 }, /* DHCP_TFTP_SERVER_NAME */
{ OPTION_STRING , 0x43 }, /* DHCP_BOOT_FILE */ { OPTION_STRING , 0x43 }, /* DHCP_BOOT_FILE */
@ -83,7 +84,6 @@ const struct dhcp_optflag dhcp_optflags[] = {
{ OPTION_U8 , 0x35 }, /* DHCP_MESSAGE_TYPE */ { OPTION_U8 , 0x35 }, /* DHCP_MESSAGE_TYPE */
{ OPTION_U16 , 0x39 }, /* DHCP_MAX_SIZE */ { OPTION_U16 , 0x39 }, /* DHCP_MAX_SIZE */
//looks like these opts will work just fine even without these defs: //looks like these opts will work just fine even without these defs:
// { OPTION_STRING , 0x3c }, /* DHCP_VENDOR */
// /* not really a string: */ // /* not really a string: */
// { OPTION_STRING , 0x3d }, /* DHCP_CLIENT_ID */ // { OPTION_STRING , 0x3d }, /* DHCP_CLIENT_ID */
{ 0, 0 } /* zeroed terminating entry */ { 0, 0 } /* zeroed terminating entry */
@ -120,6 +120,7 @@ const char dhcp_option_strings[] ALIGN1 =
"lease" "\0" /* DHCP_LEASE_TIME */ "lease" "\0" /* DHCP_LEASE_TIME */
"serverid" "\0" /* DHCP_SERVER_ID */ "serverid" "\0" /* DHCP_SERVER_ID */
"message" "\0" /* DHCP_ERR_MESSAGE */ "message" "\0" /* DHCP_ERR_MESSAGE */
"vendor" "\0" /* DHCP_VENDOR */
"tftp" "\0" /* DHCP_TFTP_SERVER_NAME*/ "tftp" "\0" /* DHCP_TFTP_SERVER_NAME*/
"bootfile" "\0" /* DHCP_BOOT_FILE */ "bootfile" "\0" /* DHCP_BOOT_FILE */
// "userclass" "\0" /* DHCP_USER_CLASS */ // "userclass" "\0" /* DHCP_USER_CLASS */

View File

@ -1296,7 +1296,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
/* not set, set the default client ID */ /* not set, set the default client ID */
client_data.clientid[1] = 3; /* DUID-LL */ client_data.clientid[1] = 3; /* DUID-LL */
client_data.clientid[3] = 1; /* ethernet */ client_data.clientid[3] = 1; /* ethernet */
clientid_mac_ptr = udhcp_insert_new_option(&client_data.options, D6_OPT_CLIENTID, clientid_mac_ptr = udhcp_insert_new_option(
&client_data.options, D6_OPT_CLIENTID,
client_data.clientid, 2+2 + 6, /*dhcp6:*/ 1); client_data.clientid, 2+2 + 6, /*dhcp6:*/ 1);
clientid_mac_ptr += 2+2 + 2+2; /* skip option code, len, DUID-LL, ethernet */ clientid_mac_ptr += 2+2 + 2+2; /* skip option code, len, DUID-LL, ethernet */
} }

View File

@ -55,8 +55,7 @@ struct tpacket_auxdata {
#if ENABLE_LONG_OPTS #if ENABLE_LONG_OPTS
static const char udhcpc_longopts[] ALIGN1 = static const char udhcpc_longopts[] ALIGN1 =
"clientid-none\0" No_argument "C" "clientid-none\0" No_argument "C"
"vendorclass\0" Required_argument "V" "vendorclass\0" Required_argument "V" //deprecated
"hostname\0" Required_argument "H"
"fqdn\0" Required_argument "F" "fqdn\0" Required_argument "F"
"interface\0" Required_argument "i" "interface\0" Required_argument "i"
"now\0" No_argument "n" "now\0" No_argument "n"
@ -84,27 +83,25 @@ static const char udhcpc_longopts[] ALIGN1 =
enum { enum {
OPT_C = 1 << 0, OPT_C = 1 << 0,
OPT_V = 1 << 1, OPT_V = 1 << 1,
OPT_H = 1 << 2, OPT_F = 1 << 2,
OPT_h = 1 << 3, OPT_i = 1 << 3,
OPT_F = 1 << 4, OPT_n = 1 << 4,
OPT_i = 1 << 5, OPT_p = 1 << 5,
OPT_n = 1 << 6, OPT_q = 1 << 6,
OPT_p = 1 << 7, OPT_R = 1 << 7,
OPT_q = 1 << 8, OPT_r = 1 << 8,
OPT_R = 1 << 9, OPT_s = 1 << 9,
OPT_r = 1 << 10, OPT_T = 1 << 10,
OPT_s = 1 << 11, OPT_t = 1 << 11,
OPT_T = 1 << 12, OPT_S = 1 << 12,
OPT_t = 1 << 13, OPT_A = 1 << 13,
OPT_S = 1 << 14, OPT_O = 1 << 14,
OPT_A = 1 << 15, OPT_o = 1 << 15,
OPT_O = 1 << 16, OPT_x = 1 << 16,
OPT_o = 1 << 17, OPT_f = 1 << 17,
OPT_x = 1 << 18, OPT_B = 1 << 18,
OPT_f = 1 << 19,
OPT_B = 1 << 20,
/* The rest has variable bit positions, need to be clever */ /* The rest has variable bit positions, need to be clever */
OPTBIT_B = 20, OPTBIT_B = 18,
USE_FOR_MMU( OPTBIT_b,) USE_FOR_MMU( OPTBIT_b,)
IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,)
IF_FEATURE_UDHCP_PORT( OPTBIT_P,) IF_FEATURE_UDHCP_PORT( OPTBIT_P,)
@ -638,10 +635,6 @@ static void add_client_options(struct dhcp_packet *packet)
packet->options[end + OPT_DATA + len] = DHCP_END; packet->options[end + OPT_DATA + len] = DHCP_END;
} }
if (client_data.vendorclass)
udhcp_add_binary_option(packet, client_data.vendorclass);
if (client_data.hostname)
udhcp_add_binary_option(packet, client_data.hostname);
if (client_data.fqdn) if (client_data.fqdn)
udhcp_add_binary_option(packet, client_data.fqdn); udhcp_add_binary_option(packet, client_data.fqdn);
@ -722,7 +715,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested)
udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested);
/* Add options: maxsize, /* Add options: maxsize,
* optionally: hostname, fqdn, vendorclass, client-id, * optionally: fqdn, client-id,
* "param req" option according to -O, options specified with -x * "param req" option according to -O, options specified with -x
*/ */
add_client_options(&packet); add_client_options(&packet);
@ -766,7 +759,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste
udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
/* Add options: maxsize, /* Add options: maxsize,
* optionally: hostname, fqdn, vendorclass, client-id, * optionally: fqdn, client-id,
* "param req" option according to -O, and options specified with -x * "param req" option according to -O, and options specified with -x
*/ */
add_client_options(&packet); add_client_options(&packet);
@ -811,7 +804,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
packet.ciaddr = ciaddr; packet.ciaddr = ciaddr;
/* Add options: maxsize, /* Add options: maxsize,
* optionally: hostname, fqdn, vendorclass, client-id, * optionally: fqdn, client-id,
* "param req" option according to -O, and options specified with -x * "param req" option according to -O, and options specified with -x
*/ */
add_client_options(&packet); add_client_options(&packet);
@ -1236,7 +1229,7 @@ int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int udhcpc_main(int argc UNUSED_PARAM, char **argv) int udhcpc_main(int argc UNUSED_PARAM, char **argv)
{ {
uint8_t *message; uint8_t *message;
const char *str_V, *str_h, *str_F, *str_r; const char *str_V, *str_F, *str_r;
IF_FEATURE_UDHCPC_ARPING(const char *str_a = "2000";) IF_FEATURE_UDHCPC_ARPING(const char *str_a = "2000";)
IF_FEATURE_UDHCP_PORT(char *str_P;) IF_FEATURE_UDHCP_PORT(char *str_P;)
uint8_t *clientid_mac_ptr; uint8_t *clientid_mac_ptr;
@ -1272,14 +1265,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* Parse command line */ /* Parse command line */
opt = getopt32long(argv, "^" opt = getopt32long(argv, "^"
/* O,x: list; -T,-t,-A take numeric param */ /* O,x: list; -T,-t,-A take numeric param */
"CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB" "CV:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB"
USE_FOR_MMU("b") USE_FOR_MMU("b")
IF_FEATURE_UDHCPC_ARPING("a::") IF_FEATURE_UDHCPC_ARPING("a::")
IF_FEATURE_UDHCP_PORT("P:") IF_FEATURE_UDHCP_PORT("P:")
"v" "v"
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */ "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
, udhcpc_longopts , udhcpc_longopts
, &str_V, &str_h, &str_h, &str_F , &str_V, &str_F
, &client_data.interface, &client_data.pidfile /* i,p */ , &client_data.interface, &client_data.pidfile /* i,p */
, &str_r /* r */ , &str_r /* r */
, &client_data.script /* s */ , &client_data.script /* s */
@ -1290,11 +1283,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_UDHCP_PORT(, &str_P) IF_FEATURE_UDHCP_PORT(, &str_P)
IF_UDHCP_VERBOSE(, &dhcp_verbose) IF_UDHCP_VERBOSE(, &dhcp_verbose)
); );
if (opt & (OPT_h|OPT_H)) {
//msg added 2011-11
bb_simple_error_msg("option -h NAME is deprecated, use -x hostname:NAME");
client_data.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
}
if (opt & OPT_F) { if (opt & OPT_F) {
/* FQDN option format: [0x51][len][flags][0][0]<fqdn> */ /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */
client_data.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3); client_data.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);
@ -1344,6 +1332,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
); );
free(optstr); free(optstr);
} }
if (str_V[0] != '\0') {
//msg added 2021-06
bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR");
udhcp_insert_new_option(
&client_data.options, DHCP_VENDOR,
str_V, strlen(str_V), /*dhcp6:*/ 0);
}
if (udhcp_read_interface(client_data.interface, if (udhcp_read_interface(client_data.interface,
&client_data.ifindex, &client_data.ifindex,
@ -1362,15 +1357,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
client_data_client_mac - 1, 1 + 6, /*dhcp6:*/ 0); client_data_client_mac - 1, 1 + 6, /*dhcp6:*/ 0);
clientid_mac_ptr += 3; /* skip option code, len, ethernet */ clientid_mac_ptr += 3; /* skip option code, len, ethernet */
} }
if (str_V[0] != '\0') {
// can drop -V, str_V, client_data.vendorclass,
// but need to add "vendor" to the list of recognized
// string opts for this to work;
// and need to tweak add_client_options() too...
// ...so the question is, should we?
//bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR");
client_data.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
}
#if !BB_MMU #if !BB_MMU
/* on NOMMU reexec (i.e., background) early */ /* on NOMMU reexec (i.e., background) early */

View File

@ -18,8 +18,6 @@ struct client_data_t {
char *pidfile; /* Optionally store the process ID */ char *pidfile; /* Optionally store the process ID */
const char *script; /* User script to run at dhcp events */ const char *script; /* User script to run at dhcp events */
struct option_set *options; /* list of DHCP options to send to server */ struct option_set *options; /* list of DHCP options to send to server */
uint8_t *vendorclass; /* Optional vendor class-id to use */
uint8_t *hostname; /* Optional hostname to use */
uint8_t *fqdn; /* Optional fully qualified domain name to use */ uint8_t *fqdn; /* Optional fully qualified domain name to use */
llist_t *envp; /* list of DHCP options used for env vars */ llist_t *envp; /* list of DHCP options used for env vars */