aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2011-09-25 13:30:11 +0200
committerBjørn Mork <bjorn@mork.no>2011-09-25 14:09:46 +0200
commit9e80cf72b366e7cdabe9cc77ef19e2ebf3609cc0 (patch)
treed9d734e34c0a1df9c249ee52c451fb90922aa0de
parent93a3818339f7831d3c5eb387957747fd55928a2e (diff)
dhcrelay: Refactor DHCPv6 interface-id adding code
simplifying a bit with a common error path, in preparation for adding more relay options. Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r--relay/dhcrelay.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
index f21f16f..1c8c522 100644
--- a/relay/dhcrelay.c
+++ b/relay/dhcrelay.c
@@ -1414,40 +1414,31 @@ process_up6(struct packet *packet, struct stream_list *dp) {
if (!option_state_allocate(&opts, MDL)) {
log_fatal("No memory for upwards options.");
}
-
- /* Add an interface-id (if used). */
- if (use_if_id) {
- int if_id;
- if (dp) {
- if_id = dp->id;
- } else if (!downstreams->next) {
- if_id = downstreams->id;
- } else {
- log_info("Don't know the interface.");
- option_state_dereference(&opts, MDL);
- return;
- }
+ /* we need a specific interface for relay options */
+ if (!dp && !downstreams->next) /* only one downstream? */
+ dp = downstreams;
- if (!save_option_buffer(&dhcpv6_universe, opts,
- NULL, (unsigned char *) &if_id,
- sizeof(int),
- D6O_INTERFACE_ID, 0)) {
- log_error("Can't save interface-id.");
- option_state_dereference(&opts, MDL);
- return;
- }
+ if (!dp && use_if_id) {
+opt_error:
+ log_info("Can't save option.");
+ option_state_dereference(&opts, MDL);
+ return;
}
+ /* Add an interface-id (if used). */
+ if (use_if_id && !save_option_buffer(&dhcpv6_universe, opts,
+ NULL, (unsigned char *) &dp->id,
+ sizeof(int),
+ D6O_INTERFACE_ID, 0))
+ goto opt_error;
+
/* Add the relay-msg carrying the packet. */
if (!save_option_buffer(&dhcpv6_universe, opts,
NULL, (unsigned char *) packet->raw,
packet->packet_length,
- D6O_RELAY_MSG, 0)) {
- log_error("Can't save relay-msg.");
- option_state_dereference(&opts, MDL);
- return;
- }
+ D6O_RELAY_MSG, 0))
+ goto opt_error;
/* Finish the relay-forward message. */
cursor += store_options6(forw_data + cursor,