Fix bad reply to DHCPCONFIRM messages (wrong message type).
authorSimon Kelley <simon@thekelleys.org.uk>
Wed, 11 Oct 2023 21:33:17 +0000 (22:33 +0100)
committerSimon Kelley <simon@thekelleys.org.uk>
Wed, 11 Oct 2023 21:33:17 +0000 (22:33 +0100)
Thanks to renmingshuai <renmingshuai@huawei.com> for
spotting the error, and making the initial patch.

src/rfc3315.c

index c2e2692..bd448c7 100644 (file)
@@ -1074,7 +1074,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbu
       
     case DHCP6CONFIRM:
       {
-       int good_addr = 0;
+       int good_addr = 0, bad_addr = 0;
 
        /* set reply message type */
        outmsgtype = DHCP6REPLY;
@@ -1096,26 +1096,24 @@ static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbu
                
                if (!address6_valid(state->context, &req_addr, tagif, 1))
                  {
-                   o1 = new_opt6(OPTION6_STATUS_CODE);
-                   put_opt6_short(DHCP6NOTONLINK);
-                   put_opt6_string(_("confirm failed"));
-                   end_opt6(o1);
+                   bad_addr = 1;
                    log6_quiet(state, "DHCPREPLY", &req_addr, _("confirm failed"));
-                   return 1;
                  }
-
-               good_addr = 1;
-               log6_quiet(state, "DHCPREPLY", &req_addr, state->hostname);
+               else
+                 {
+                   good_addr = 1;
+                   log6_quiet(state, "DHCPREPLY", &req_addr, state->hostname);
+                 }
              }
          }      
        
        /* No addresses, no reply: RFC 3315 18.2.2 */
-       if (!good_addr)
+       if (!good_addr && !bad_addr)
          return 0;
 
        o1 = new_opt6(OPTION6_STATUS_CODE);
-       put_opt6_short(DHCP6SUCCESS );
-       put_opt6_string(_("all addresses still on link"));
+       put_opt6_short(bad_addr ? DHCP6NOTONLINK : DHCP6SUCCESS);
+       put_opt6_string(bad_addr ? (_("confirm failed")) : (_("all addresses still on link")));
        end_opt6(o1);
        break;
     }