The only call to dname_enc is with cstr = NULL, so most of dname_enc's logic is 
not used.
Therefore, we can directly call convert_dname and shrink the binary size.

function                                             old     new   delta
convert_dname                                          -     143    +143
attach_option                                        463     493     +30
dname_enc                                            445       -    -445
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/0 up/down: 173/-445)         Total: -272
bytes
   text    data     bss     dec     hex filename
 993252   16923    1872 1012047   f714f busybox_old
 992980   16923    1872 1011775   f703f busybox_unstripped

Signed-off-by: Martin Lewis <martin.lewis....@gmail.com>
---
 networking/udhcp/common.c       | 6 +++++-
 networking/udhcp/common.h       | 1 +
 networking/udhcp/domain_codec.c | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index 9ec752dfc..f609bcfdb 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -431,7 +431,11 @@ static NOINLINE void attach_option(
 #if ENABLE_FEATURE_UDHCP_RFC3397
        if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
                /* reuse buffer and length for RFC1035-formatted string */
-               allocated = buffer = (char *)dname_enc(NULL, 0, buffer, 
&length);
+               allocated = buffer = (char *)convert_dname(buffer);
+               if (buffer == NULL)
+                       length = 0;
+               else
+                       length = strlen(buffer) + 1; /* including NUL */
        }
 #endif
 
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 60255eefa..7aeeb5152 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -219,6 +219,7 @@ void udhcp_add_simple_option(struct dhcp_packet *packet, 
uint8_t code, uint32_t
 #if ENABLE_FEATURE_UDHCP_RFC3397 || ENABLE_FEATURE_UDHCPC6_RFC3646 || 
ENABLE_FEATURE_UDHCPC6_RFC4704
 char *dname_dec(const uint8_t *cstr, int clen, const char *pre) FAST_FUNC;
 uint8_t *dname_enc(const uint8_t *cstr, int clen, const char *src, int 
*retlen) FAST_FUNC;
+uint8_t *convert_dname(const char *src);
 #endif
 struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t 
code) FAST_FUNC;
 
diff --git a/networking/udhcp/domain_codec.c b/networking/udhcp/domain_codec.c
index b7a3a5353..b5df48d87 100644
--- a/networking/udhcp/domain_codec.c
+++ b/networking/udhcp/domain_codec.c
@@ -113,7 +113,7 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, 
const char *pre)
  * RFC1035 encoding "\003foo\004blah\003com\000". Return allocated string, or
  * NULL if an error occurs.
  */
-static uint8_t *convert_dname(const char *src)
+uint8_t *convert_dname(const char *src)
 {
        uint8_t c, *res, *lenptr, *dst;
        int len;
-- 
2.11.0

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to