]> git.proxmox.com Git - mirror_lxc.git/commitdiff
fix for issue 4026: set broadcast to 0.0.0.0 for /31 and /32
authorMarc E. Fiuczynski <mfiuczyn@akamai.com>
Mon, 13 Jun 2022 12:43:14 +0000 (08:43 -0400)
committerMarc E. Fiuczynski <mfiuczyn@akamai.com>
Mon, 27 Jun 2022 19:15:48 +0000 (15:15 -0400)
Signed-off-by: Marc E. Fiuczynski <mfiuczyn@akamai.com>
src/lxc/confile.c

index f5ff9f6204d2068d56d712cfc9ed7bde1fd872ad..7966d32e85115bb7bbb48fbc2548dd402c0b533a 100644 (file)
@@ -899,13 +899,19 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
 
        /* If no broadcast address, compute one from the prefix and address. */
        if (!bcast) {
-               unsigned int shift = LAST_BIT_PER_TYPE(inetdev->prefix);
+               /* 0<=inetdev->prefix<=32 */
+               switch (inetdev->prefix) {
+               case 32: /* single IPv4 network */
+                       ; /* fall thru */
+               case 31: /* RFC 3021 point to point network */
+                       inetdev->bcast.s_addr = INADDR_ANY;
+                       break;
 
-               inetdev->bcast.s_addr = inetdev->addr.s_addr;
-               if (inetdev->prefix < shift)
-                       shift = inetdev->prefix;
-               inetdev->bcast.s_addr |= htonl(INADDR_BROADCAST >> shift);
-       }
+               default:
+                       inetdev->bcast.s_addr |= htonl(INADDR_BROADCAST >> inetdev->prefix);
+                       break;
+               }
+        }
 
        list_add_tail(&inetdev->head, &netdev->ipv4_addresses);
        move_ptr(inetdev);