|
@@ -216,6 +216,21 @@ static bool IsOnLoopbackNetwork(in_addr_t ip_addr)
|
|
|
return (ip & IN_CLASSA_NET) == (INADDR_LOOPBACK & IN_CLASSA_NET);
|
|
return (ip & IN_CLASSA_NET) == (INADDR_LOOPBACK & IN_CLASSA_NET);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/** Check if an IP address is either the network or the broadcast address
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param ip_addr IP address in network byte order
|
|
|
|
|
+ * @param net_mask network mask in network byte order
|
|
|
|
|
+ * @return status
|
|
|
|
|
+ *
|
|
|
|
|
+ * Check if an IP address is either the network or the broadcast address.
|
|
|
|
|
+ * In this case it is not a valid IP address for a host.
|
|
|
|
|
+ * This check is endian agnostic.
|
|
|
|
|
+ */
|
|
|
|
|
+static bool IsNetworkOrBroadcastIp(in_addr_t ip_addr, in_addr_t net_mask) {
|
|
|
|
|
+ return ((ip_addr & net_mask) == ip_addr) || /* is network address */
|
|
|
|
|
+ ((ip_addr | ~net_mask) == ip_addr); /* is broadcast address */
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/** Check the Interface configuration being valid according to EIP specification
|
|
/** Check the Interface configuration being valid according to EIP specification
|
|
|
*
|
|
*
|
|
|
* In Vol. 2 the "Table 5-4.3 Instance Attributes" provides some information
|
|
* In Vol. 2 the "Table 5-4.3 Instance Attributes" provides some information
|
|
@@ -228,13 +243,14 @@ static bool IsOnLoopbackNetwork(in_addr_t ip_addr)
|
|
|
* - MASK: IP is a valid network mask
|
|
* - MASK: IP is a valid network mask
|
|
|
* - ABC: IP is in class A, B or C
|
|
* - ABC: IP is in class A, B or C
|
|
|
* - NLCL: IP is not localhost aka. INADDR_LOOPBACK
|
|
* - NLCL: IP is not localhost aka. INADDR_LOOPBACK
|
|
|
|
|
+ * - NB: IP is neither network or broadcast address (using network_mask)
|
|
|
*
|
|
*
|
|
|
* This is the table which checks are applied to what IP:
|
|
* This is the table which checks are applied to what IP:
|
|
|
- * N0 | MASK | ABC | NLCL | IP address
|
|
|
|
|
- * + | - | + | + | ip_address
|
|
|
|
|
- * - | + | - | - | network_mask
|
|
|
|
|
- * - | - | + | + | gateway
|
|
|
|
|
- * - | - | + | - | name_server / name_server_2
|
|
|
|
|
|
|
+ * N0 | MASK | ABC | NLCL | NB | IP address
|
|
|
|
|
+ * + | - | + | + | + | ip_address
|
|
|
|
|
+ * - | + | - | - | - | network_mask
|
|
|
|
|
+ * - | - | + | + | + | gateway
|
|
|
|
|
+ * - | - | + | - | - | name_server / name_server_2
|
|
|
* A configured gateway must be reachable according to the network mask.
|
|
* A configured gateway must be reachable according to the network mask.
|
|
|
*/
|
|
*/
|
|
|
static bool IsValidNetworkConfig(const CipTcpIpInterfaceConfiguration *if_cfg)
|
|
static bool IsValidNetworkConfig(const CipTcpIpInterfaceConfiguration *if_cfg)
|
|
@@ -256,6 +272,12 @@ static bool IsValidNetworkConfig(const CipTcpIpInterfaceConfiguration *if_cfg)
|
|
|
IsOnLoopbackNetwork(if_cfg->gateway)) {
|
|
IsOnLoopbackNetwork(if_cfg->gateway)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+ /* Check NB */
|
|
|
|
|
+ if (IsNetworkOrBroadcastIp(if_cfg->ip_address, if_cfg->network_mask) ||
|
|
|
|
|
+ (INADDR_ANY != ntohl(if_cfg->gateway) &&
|
|
|
|
|
+ IsNetworkOrBroadcastIp(if_cfg->gateway, if_cfg->network_mask))) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
if (INADDR_ANY != ntohl(if_cfg->gateway) &&
|
|
if (INADDR_ANY != ntohl(if_cfg->gateway) &&
|
|
|
INADDR_ANY != ntohl(if_cfg->network_mask)) {
|
|
INADDR_ANY != ntohl(if_cfg->network_mask)) {
|
|
|
/* gateway is configured. Check if it is reachable. */
|
|
/* gateway is configured. Check if it is reachable. */
|