return tnl->ip_src ? in6_addr_mapped_ipv4(tnl->ip_src) : tnl->ipv6_src;
}
+/* Returns true if 's' consists entirely of hex digits, false otherwise. */
+static bool
+is_all_hex(const char *s)
+{
+ return s[strspn(s, "0123456789abcdefABCDEF")] == '\0';
+}
+
/* Parses 's' as a 16-digit hexadecimal number representing a datapath ID. On
* success stores the dpid into '*dpidp' and returns true, on failure stores 0
* into '*dpidp' and returns false.
bool
dpid_from_string(const char *s, uint64_t *dpidp)
{
- *dpidp = (strlen(s) == 16 && strspn(s, "0123456789abcdefABCDEF") == 16
+ size_t len = strlen(s);
+ *dpidp = ((len == 16 && is_all_hex(s))
+ || (len <= 18 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')
+ && is_all_hex(s + 2))
? strtoull(s, NULL, 16)
: 0);
return *dpidp != 0;
OVS_VSWITCHD_STOP(['/ignoring bridge with invalid name/d'])
AT_CLEANUP
+
+dnl ----------------------------------------------------------------------
+AT_SETUP([ovs-vswitchd - set datapath IDs])
+OVS_VSWITCHD_START([remove bridge br0 other-config datapath-id])
+
+# Get the default dpid and verify that it is of the expected form.
+AT_CHECK([ovs-vsctl --timeout=10 wait-until bridge br0 datapath-id!='[[]]'])
+AT_CHECK([ovs-vsctl get bridge br0 datapath-id], [0], [stdout])
+orig_dpid=$(tr -d \" < stdout)
+AT_CHECK([sed 's/[[0-9a-f]]/x/g' stdout], [0], ["xxxxxxxxxxxxxxxx"
+])
+AT_CHECK_UNQUOTED([ovs-ofctl show br0 | strip_xids | head -1], [0], [dnl
+OFPT_FEATURES_REPLY: dpid:$orig_dpid
+])
+
+# Set a dpid with 16 hex digits.
+AT_CHECK([ovs-vsctl set bridge br0 other-config:datapath-id=0123456789abcdef])
+AT_CHECK([ovs-vsctl --timeout=10 wait-until bridge br0 datapath-id=0123456789abcdef])
+AT_CHECK([ovs-ofctl show br0 | strip_xids | head -1], [0], [dnl
+OFPT_FEATURES_REPLY: dpid:0123456789abcdef
+])
+
+# Set a dpif with 0x prefix.
+AT_CHECK([ovs-vsctl set bridge br0 other-config:datapath-id=0x5ad515c0])
+AT_CHECK([ovs-vsctl --timeout=10 wait-until bridge br0 datapath-id=000000005ad515c0])
+AT_CHECK([ovs-ofctl show br0 | strip_xids | head -1], [0], [dnl
+OFPT_FEATURES_REPLY: dpid:000000005ad515c0
+])
+
+# Set invalid all-zeros dpid and make sure that the default reappears.
+AT_CHECK([ovs-vsctl set bridge br0 other-config:datapath-id=0x00])
+AT_CHECK([ovs-vsctl --timeout=10 wait-until bridge br0 datapath-id=$orig_dpid])
+AT_CHECK_UNQUOTED([ovs-ofctl show br0 | strip_xids | head -1], [0], [dnl
+OFPT_FEATURES_REPLY: dpid:$orig_dpid
+])
+
+OVS_VSWITCHD_STOP
+AT_CLEANUP
</column>
<column name="other_config" key="datapath-id">
- Exactly 16 hex digits to set the OpenFlow datapath ID to a specific
- value. May not be all-zero.
+ Overrides the default OpenFlow datapath ID, setting it to the specified
+ value specified in hex. The value must either have a <code>0x</code>
+ prefix or be exactly 16 hex digits long. May not be all-zero.
</column>
<column name="other_config" key="dp-desc">