Mercurial > hg > dhcpcd
changeset 2171:8a1a9d940b2c draft
I had no idea what I was smoking when I moved these to dhcp-common.
Move them back, mark them static and remove the unused.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Fri, 29 Nov 2013 12:48:52 +0000 |
| parents | 6787ee3545b5 |
| children | bb54bdee6a5d |
| files | dhcp-common.c dhcp-common.h dhcp.c dhcp.h |
| diffstat | 4 files changed, 34 insertions(+), 102 deletions(-) [+] |
line wrap: on
line diff
--- a/dhcp-common.c Fri Nov 29 12:02:45 2013 +0000 +++ b/dhcp-common.c Fri Nov 29 12:48:52 2013 +0000 @@ -98,53 +98,6 @@ return 0; } -int -dhcp_getaddr(struct in_addr *a, const uint8_t *p, size_t pl) -{ - - if (!p || pl < sizeof(a->s_addr)) - return -1; - memcpy(&a->s_addr, p, sizeof(a->s_addr)); - return 0; -} - -int -dhcp_getuint32(uint32_t *i, const uint8_t *p, size_t pl) -{ - uint32_t d; - - if (!p || pl < sizeof(d)) - return -1; - memcpy(&d, p, sizeof(d)); - if (i) - *i = ntohl(d); - return 0; -} - -int -dhcp_getuint16(uint16_t *i, const uint8_t *p, size_t pl) -{ - uint16_t d; - - if (!p || pl < sizeof(d)) - return -1; - memcpy(&d, p, sizeof(d)); - if (i) - *i = ntohs(d); - return 0; -} - -int -dhcp_getuint8(uint8_t *i, const uint8_t *p, __unused size_t pl) -{ - - if (!p) - return -1; - if (i) - *i = *(p); - return 0; -} - size_t encode_rfc1035(const char *src, uint8_t *dst) {
--- a/dhcp-common.h Fri Nov 29 12:02:45 2013 +0000 +++ b/dhcp-common.h Fri Nov 29 12:48:52 2013 +0000 @@ -88,11 +88,6 @@ #define has_option_mask(var, val) (var[val >>3] & (1 << (val & 7))) int make_option_mask(const struct dhcp_opt *, uint8_t *, const char *, int); -int dhcp_getaddr(struct in_addr *, const uint8_t *, size_t); -int dhcp_getuint32(uint32_t *, const uint8_t *, size_t); -int dhcp_getuint16(uint16_t *, const uint8_t *, size_t); -int dhcp_getuint8(uint8_t *, const uint8_t *, size_t); - size_t encode_rfc1035(const char *src, uint8_t *dst); ssize_t decode_rfc3397(char *, ssize_t, int, const uint8_t *); ssize_t print_string(char *, ssize_t, int, const uint8_t *);
--- a/dhcp.c Fri Nov 29 12:02:45 2013 +0000 +++ b/dhcp.c Fri Nov 29 12:48:52 2013 +0000 @@ -265,7 +265,7 @@ uint8_t overl = 0; uint8_t *bp = NULL; const uint8_t *op = NULL; - ssize_t bl = 0; + int bl = 0; while (p < e) { o = *p++; @@ -336,38 +336,41 @@ const uint8_t *p; int len; - p = get_option(dhcp, option, &len, NULL); - return dhcp_getaddr(a, p, len); + p = get_option(dhcp, option, &len); + if (!p || len < (ssize_t)sizeof(a->s_addr)) + return -1; + memcpy(&a->s_addr, p, sizeof(a->s_addr)); + return 0; } -int +static int get_option_uint32(uint32_t *i, const struct dhcp_message *dhcp, uint8_t option) { const uint8_t *p; int len; + uint32_t d; - p = get_option(dhcp, option, &len, NULL); - return dhcp_getuint32(i, p, len); + p = get_option(dhcp, option, &len); + if (!p || len < (ssize_t)sizeof(d)) + return -1; + memcpy(&d, p, sizeof(d)); + if (i) + *i = ntohl(d); + return 0; } -int -get_option_uint16(uint16_t *i, const struct dhcp_message *dhcp, uint8_t option) -{ - const uint8_t *p; - int len; - - p = get_option(dhcp, option, &len, NULL); - return dhcp_getuint16(i, p, len); -} - -int +static int get_option_uint8(uint8_t *i, const struct dhcp_message *dhcp, uint8_t option) { const uint8_t *p; int len; - p = get_option(dhcp, option, &len, NULL); - return dhcp_getuint8(i, p, len); + p = get_option(dhcp, option, &len); + if (!p || len < (ssize_t)sizeof(*p)) + return -1; + if (i) + *i = *(p); + return 0; } ssize_t @@ -600,30 +603,14 @@ char * get_option_string(const struct dhcp_message *dhcp, uint8_t option) { - int type = 0; int len; const uint8_t *p; char *s; - p = get_option(dhcp, option, &len, &type); - if (!p || *p == '\0') + p = get_option(dhcp, option, &len); + if (!p || len == 0 || *p == '\0') return NULL; - if (type & RFC3397) { - type = decode_rfc3397(NULL, 0, len, p); - if (!type) { - errno = EINVAL; - return NULL; - } - s = malloc(sizeof(char) * type); - if (s) - decode_rfc3397(s, type, len, p); - return s; - } - - if (type & RFC3361) - return decode_rfc3361(len, p); - s = malloc(sizeof(char) * (len + 1)); if (s) { memcpy(s, p, len); @@ -677,12 +664,12 @@ /* If we have CSR's then we MUST use these only */ if (!has_option_mask(ifo->nomask, DHO_CSR)) - p = get_option(dhcp, DHO_CSR, &len, NULL); + p = get_option(dhcp, DHO_CSR, &len); else p = NULL; /* Check for crappy MS option */ if (!p && !has_option_mask(ifo->nomask, DHO_MSCSR)) { - p = get_option(dhcp, DHO_MSCSR, &len, NULL); + p = get_option(dhcp, DHO_MSCSR, &len); if (p) csr = "MS "; } @@ -707,7 +694,7 @@ } TAILQ_INIT(routes); if (!has_option_mask(ifo->nomask, DHO_STATICROUTE)) - p = get_option(dhcp, DHO_STATICROUTE, &len, NULL); + p = get_option(dhcp, DHO_STATICROUTE, &len); else p = NULL; if (p) { @@ -730,7 +717,7 @@ /* Now grab our routers */ if (!has_option_mask(ifo->nomask, DHO_ROUTER)) - p = get_option(dhcp, DHO_ROUTER, &len, NULL); + p = get_option(dhcp, DHO_ROUTER, &len); else p = NULL; if (p) { @@ -1157,7 +1144,7 @@ continue; if (dhcp_getoverride(ifo, opt->option, 1)) continue; - p = get_option(dhcp, opt->option, &pl, NULL); + p = get_option(dhcp, opt->option, &pl); if (!p) continue; e += dhcp_envoption(NULL, prefix, "", ifp->name, @@ -1177,7 +1164,7 @@ continue; if (dhcp_getoverride(ifo, opt->option, 0)) continue; - p = get_option(dhcp, opt->option, &pl, NULL); + p = get_option(dhcp, opt->option, &pl); if (!p) continue; e += dhcp_envoption(NULL, prefix, "", ifp->name, @@ -1189,7 +1176,7 @@ { if (has_option_mask(ifo->nomask, opt->option)) continue; - p = get_option(dhcp, opt->option, &pl, NULL); + p = get_option(dhcp, opt->option, &pl); if (!p) continue; e += dhcp_envoption(NULL, prefix, "", ifp->name, @@ -1230,7 +1217,7 @@ continue; if (dhcp_getoverride(ifo, opt->option, 1)) continue; - p = get_option(dhcp, opt->option, &pl, NULL); + p = get_option(dhcp, opt->option, &pl); if (!p) continue; /* No override, which means it's not embedded, so just @@ -1251,7 +1238,7 @@ continue; if (dhcp_getoverride(ifo, opt->option, 0)) continue; - if ((p = get_option(dhcp, opt->option, &pl, NULL))) + if ((p = get_option(dhcp, opt->option, &pl))) ep += dhcp_envoption(ep, prefix, "", ifp->name, opt, dhcp_getoption, p, pl); } @@ -1262,7 +1249,7 @@ { if (has_option_mask(ifo->nomask, opt->option)) continue; - if ((p = get_option(dhcp, opt->option, &pl, NULL))) + if ((p = get_option(dhcp, opt->option, &pl))) ep += dhcp_envoption(ep, prefix, "", ifp->name, opt, dhcp_getoption, p, pl); }
--- a/dhcp.h Fri Nov 29 12:02:45 2013 +0000 +++ b/dhcp.h Fri Nov 29 12:48:52 2013 +0000 @@ -250,9 +250,6 @@ void dhcp_printoptions(void); char *get_option_string(const struct dhcp_message *, uint8_t); int get_option_addr(struct in_addr *, const struct dhcp_message *, uint8_t); -int get_option_uint32(uint32_t *, const struct dhcp_message *, uint8_t); -int get_option_uint16(uint16_t *, const struct dhcp_message *, uint8_t); -int get_option_uint8(uint8_t *, const struct dhcp_message *, uint8_t); #define is_bootp(m) (m && \ !IN_LINKLOCAL(htonl((m)->yiaddr)) && \ get_option_uint8(NULL, m, DHO_MESSAGETYPE) == -1)
