dhcpc: refactor xmalloc_optname_optval to shrink binary size
function old new delta len_of_option_as_string 14 13 -1 dhcp_option_lengths 14 13 -1 udhcp_str2optset 641 637 -4 static.xmalloc_optname_optval 777 718 -59 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-65) Total: -65 bytes Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
17764603f2
commit
d30d1ebc11
@ -78,7 +78,7 @@ struct BUG_bad_sizeof_struct_ip_udp_dhcp_packet {
|
|||||||
/*** Options ***/
|
/*** Options ***/
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OPTION_IP = 1,
|
OPTION_IP = 0,
|
||||||
OPTION_IP_PAIR,
|
OPTION_IP_PAIR,
|
||||||
OPTION_STRING,
|
OPTION_STRING,
|
||||||
/* Opts of STRING_HOST type will be sanitized before they are passed
|
/* Opts of STRING_HOST type will be sanitized before they are passed
|
||||||
|
@ -208,9 +208,8 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_
|
|||||||
case OPTION_IP:
|
case OPTION_IP:
|
||||||
case OPTION_IP_PAIR:
|
case OPTION_IP_PAIR:
|
||||||
dest += sprint_nip(dest, "", option);
|
dest += sprint_nip(dest, "", option);
|
||||||
if (type == OPTION_IP)
|
if (type == OPTION_IP_PAIR)
|
||||||
break;
|
dest += sprint_nip(dest, "/", option + 4);
|
||||||
dest += sprint_nip(dest, "/", option + 4);
|
|
||||||
break;
|
break;
|
||||||
// case OPTION_BOOLEAN:
|
// case OPTION_BOOLEAN:
|
||||||
// dest += sprintf(dest, *option ? "yes" : "no");
|
// dest += sprintf(dest, *option ? "yes" : "no");
|
||||||
@ -312,7 +311,7 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_
|
|||||||
* IPv4MaskLen <= 32,
|
* IPv4MaskLen <= 32,
|
||||||
* 6rdPrefixLen <= 128,
|
* 6rdPrefixLen <= 128,
|
||||||
* 6rdPrefixLen + (32 - IPv4MaskLen) <= 128
|
* 6rdPrefixLen + (32 - IPv4MaskLen) <= 128
|
||||||
* (2nd condition need no check - it follows from 1st and 3rd).
|
* (2nd condition needs no check - it follows from 1st and 3rd).
|
||||||
* Else, return envvar with empty value ("optname=")
|
* Else, return envvar with empty value ("optname=")
|
||||||
*/
|
*/
|
||||||
if (len >= (1 + 1 + 16 + 4)
|
if (len >= (1 + 1 + 16 + 4)
|
||||||
@ -326,17 +325,12 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_
|
|||||||
/* 6rdPrefix */
|
/* 6rdPrefix */
|
||||||
dest += sprint_nip6(dest, /* "", */ option);
|
dest += sprint_nip6(dest, /* "", */ option);
|
||||||
option += 16;
|
option += 16;
|
||||||
len -= 1 + 1 + 16 + 4;
|
len -= 1 + 1 + 16;
|
||||||
/* "+ 4" above corresponds to the length of IPv4 addr
|
*dest++ = ' ';
|
||||||
* we consume in the loop below */
|
/* 6rdBRIPv4Address(es), use common IPv4 logic to process them */
|
||||||
while (1) {
|
type = OPTION_IP;
|
||||||
/* 6rdBRIPv4Address(es) */
|
optlen = 4;
|
||||||
dest += sprint_nip(dest, " ", option);
|
continue;
|
||||||
option += 4;
|
|
||||||
len -= 4; /* do we have yet another 4+ bytes? */
|
|
||||||
if (len < 0)
|
|
||||||
break; /* no */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -358,23 +352,18 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_
|
|||||||
*/
|
*/
|
||||||
option++;
|
option++;
|
||||||
len--;
|
len--;
|
||||||
|
if (option[-1] == 1) {
|
||||||
|
/* use common IPv4 logic to process IP addrs */
|
||||||
|
type = OPTION_IP;
|
||||||
|
optlen = 4;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (option[-1] == 0) {
|
if (option[-1] == 0) {
|
||||||
dest = dname_dec(option, len, ret);
|
dest = dname_dec(option, len, ret);
|
||||||
if (dest) {
|
if (dest) {
|
||||||
free(ret);
|
free(ret);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
if (option[-1] == 1) {
|
|
||||||
const char *pfx = "";
|
|
||||||
while (1) {
|
|
||||||
len -= 4;
|
|
||||||
if (len < 0)
|
|
||||||
break;
|
|
||||||
dest += sprint_nip(dest, pfx, option);
|
|
||||||
pfx = " ";
|
|
||||||
option += 4;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user