]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
inet: Add function for checking multicast addresses
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 1 Oct 2020 18:26:04 +0000 (13:26 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 1 Oct 2020 18:26:57 +0000 (13:26 -0500)
src/lib/util/inet.c
src/lib/util/inet.h
src/modules/proto_dhcpv6/proto_dhcpv6_udp.c

index 62ecf309cf6f37053ade89fce343cdee47d83ce2..d4a98404145750433c1a253f73df0ab1816c32a8 100644 (file)
@@ -82,6 +82,36 @@ int fr_ipaddr_is_inaddr_any(fr_ipaddr_t const *ipaddr)
        return 0;
 }
 
+/** Determine if an address is a multicast address
+ *
+ * @param ipaddr to check.
+ * @return
+ *     - 0 if it's not.
+ *     - 1 if it is.
+ *     - -1 on error.
+ */
+int fr_ipaddr_is_multicast(fr_ipaddr_t const *ipaddr)
+{
+       if (ipaddr->af == AF_INET) {
+               /*
+                *      224.0.0.0 (3758096384) - 239.255.255.255 (4026531839)
+                */
+               if ((ipaddr->addr.v4.s_addr >= 3758096384) && (ipaddr->addr.v4.s_addr <= 4026531839)) return 1;
+#ifdef HAVE_STRUCT_SOCKADDR_IN6
+       } else if (ipaddr->af == AF_INET6) {
+               if (IN6_IS_ADDR_MULTICAST(&(ipaddr->addr.v6))) {
+                       return 1;
+               }
+#endif
+
+       } else {
+               fr_strerror_printf("Unknown address family");
+               return -1;
+       }
+
+       return 0;
+}
+
 /** Determine if an address is a prefix
  *
  * @param ipaddr to check.
index 3a1e6da80a0991da5d889df357f4f56fdcd7c230..7701c578b1dfb37325dfe92f790f53973a9a41d0 100644 (file)
@@ -113,6 +113,7 @@ extern bool fr_hostname_lookups; /* do hostname -> IP lookups? */
  *     Utility functions
  */
 int    fr_ipaddr_is_inaddr_any(fr_ipaddr_t const *ipaddr);
+int    fr_ipaddr_is_multicast(fr_ipaddr_t const *ipaddr);
 int    fr_ipaddr_is_prefix(fr_ipaddr_t const *ipaddr);
 
 /*
index 86fc09d0ca3cb5fba1a12289b3753d87db42fad1..777a23ec18dbb4bcd04a64105d14637ee3c324b7 100644 (file)
@@ -285,7 +285,7 @@ static void mod_network_get(void *instance, int *ipproto, bool *dynamic_clients,
 }
 
 
-/** Open a UDP listener for DHCPV4
+/** Open a UDP listener for DHCPv6
  *
  */
 static int mod_open(fr_listen_t *li)
@@ -479,7 +479,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs)
        /*
         *      Remember if we're a multicast socket.
         */
-       inst->multicast = (inst->ipaddr.addr.v6.s6_addr[0] == 0xff);
+       inst->multicast = (fr_ipaddr_is_multicast(&inst->ipaddr) == 1);
 
        /*
         *      Set src_ipaddr to ipaddr if not otherwise specified
@@ -507,7 +507,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs)
 
                } else {
                        /*
-                        *      Multicase addresses MUST specify an interface.
+                        *      Multicast addresses MUST specify an interface.
                         */
                        if (!inst->interface) goto interface_fail;