summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
acb4fc0)
This will allow callers of odhcp6_add_state parsing a command line option :
generate a syslog error in case of failure
bail out with return an error code
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
case 'V':
l = script_unhexlify(buf, sizeof(buf), optarg);
case 'V':
l = script_unhexlify(buf, sizeof(buf), optarg);
+ if (l) {
+ if (odhcp6c_add_state(STATE_VENDORCLASS, buf, l)) {
+ syslog(LOG_ERR, "Failed to set vendor-class option");
+ return 1;
+ }
+ } else
-
- odhcp6c_add_state(STATE_VENDORCLASS, buf, l);
else
prefix.iaid = htonl(++ia_pd_iaid_index);
else
prefix.iaid = htonl(++ia_pd_iaid_index);
- odhcp6c_add_state(STATE_IA_PD_INIT, &prefix, sizeof(prefix));
+ if (odhcp6c_add_state(STATE_IA_PD_INIT, &prefix, sizeof(prefix))) {
+ syslog(LOG_ERR, "Failed to set request IPv6-Prefix");
+ return 1;
+ }
buf[1] = DHCPV6_OPT_CLIENTID;
buf[2] = 0;
buf[3] = l;
buf[1] = DHCPV6_OPT_CLIENTID;
buf[2] = 0;
buf[3] = l;
- odhcp6c_add_state(STATE_CLIENT_ID, buf, l + 4);
+ if (odhcp6c_add_state(STATE_CLIENT_ID, buf, l + 4)) {
+ syslog(LOG_ERR, "Failed to override client-ID");
+ return 1;
+ }
} else
help = true;
break;
} else
help = true;
break;
else if (optpos[0])
optarg = &optpos[1];
else if (optpos[0])
optarg = &optpos[1];
- odhcp6c_add_state(STATE_ORO, &opttype, 2);
+ if (odhcp6c_add_state(STATE_ORO, &opttype, 2)) {
+ syslog(LOG_ERR, "Failed to add requested option");
+ return 1;
+ }
case 'u':
optlen = htons(strlen(optarg));
case 'u':
optlen = htons(strlen(optarg));
- odhcp6c_add_state(STATE_USERCLASS, &optlen, 2);
- odhcp6c_add_state(STATE_USERCLASS, optarg, strlen(optarg));
+ if (odhcp6c_add_state(STATE_USERCLASS, &optlen, 2) ||
+ odhcp6c_add_state(STATE_USERCLASS, optarg, strlen(optarg))) {
+ syslog(LOG_ERR, "Failed to set user-class option");
+ return 1;
+ }
-void odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len)
+int odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len)
{
uint8_t *n = odhcp6c_resize_state(state, len);
{
uint8_t *n = odhcp6c_resize_state(state, len);
- if (n)
- memcpy(n, data, len);
+ if (!n)
+ return -1;
+
+ memcpy(n, data, len);
+
+ return 0;
}
int odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len)
}
int odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len)
x->t1 = new->t1;
x->t2 = new->t2;
x->iaid = new->iaid;
x->t1 = new->t1;
x->t2 = new->t2;
x->iaid = new->iaid;
- } else
- odhcp6c_add_state(state, new, odhcp6c_entry_size(new));
+ } else if (odhcp6c_add_state(state, new, odhcp6c_entry_size(new)))
+ return false;
} else if (x)
odhcp6c_remove_state(state, ((uint8_t*)x) - start, odhcp6c_entry_size(x));
} else if (x)
odhcp6c_remove_state(state, ((uint8_t*)x) - start, odhcp6c_entry_size(x));
// State manipulation
void odhcp6c_clear_state(enum odhcp6c_state state);
// State manipulation
void odhcp6c_clear_state(enum odhcp6c_state state);
-void odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len);
+int odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len);
void odhcp6c_append_state(enum odhcp6c_state state, const void *data, size_t len);
int odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len);
size_t odhcp6c_remove_state(enum odhcp6c_state state, size_t offset, size_t len);
void odhcp6c_append_state(enum odhcp6c_state state, const void *data, size_t len);
int odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len);
size_t odhcp6c_remove_state(enum odhcp6c_state state, size_t offset, size_t len);