Send ADVERTISE and CONFIG_ACK in one go
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sat, 29 Feb 2020 20:41:15 +0000 (21:41 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sat, 29 Feb 2020 22:33:47 +0000 (23:33 +0100)
nmrp.c

diff --git a/nmrp.c b/nmrp.c
index e4fcbf1bec742d1d0c9455c768bf4fcfda5fc87c..49070e948adf2889f09ec735517b5ae6471ca3f1 100644 (file)
--- a/nmrp.c
+++ b/nmrp.c
@@ -472,7 +472,6 @@ int nmrp_do(struct nmrpd_args *args)
        memcpy(tx.eh.ether_dhost, dest, 6);
        tx.eh.ether_type = htons(ETH_P_NMRP);
 
-       msg_mkadvertise(&tx.msg, "NTGR");
 
        i = 0;
        upload_ok = 0;
@@ -484,8 +483,13 @@ int nmrp_do(struct nmrpd_args *args)
                fflush(stdout);
                i = (i + 1) & 3;
 
+               msg_mkadvertise(&tx.msg, "NTGR");
+               if (pkt_send(sock, &tx) < 0) {
+                       goto out;
+               }
+
+               msg_mkconfack(&tx.msg, ipaddr.s_addr, ipmask.s_addr, region);
                if (pkt_send(sock, &tx) < 0) {
-                       xperror("sendto");
                        goto out;
                }
 
@@ -510,8 +514,15 @@ int nmrp_do(struct nmrpd_args *args)
                }
        }
 
+
        printf("\n");
 
+       memcpy(tx.eh.ether_dhost, rx.eh.ether_shost, 6);
+
+       if (ethsock_arp_add(sock, rx.eh.ether_shost, ipaddr.s_addr, &arp_undo) != 0) {
+               goto out;
+       }
+
        expect = NMRP_C_CONF_REQ;
        ulreqs = 0;
        kareqs = 0;
@@ -539,15 +550,9 @@ int nmrp_do(struct nmrpd_args *args)
                                printf("Received configuration request from %s.\n",
                                                mac_to_str(rx.eh.ether_shost));
 
-                               memcpy(tx.eh.ether_dhost, rx.eh.ether_shost, 6);
-
                                printf("Sending configuration: %s/%d.\n",
                                                args->ipaddr, bitcount(ipmask.s_addr));
 
-                               if (ethsock_arp_add(sock, rx.eh.ether_shost, ipaddr.s_addr, &arp_undo) != 0) {
-                                       goto out;
-                               }
-
                                break;
                        case NMRP_C_TFTP_UL_REQ:
                                if (!upload_ok) {
@@ -651,7 +656,6 @@ int nmrp_do(struct nmrpd_args *args)
 
                if (tx.msg.code != NMRP_C_NONE) {
                        if (pkt_send(sock, &tx) < 0) {
-                               xperror("sendto");
                                goto out;
                        }