summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Grosbein <eugen@FreeBSD.org>2018-07-23 07:11:58 +0000
committerEugene Grosbein <eugen@FreeBSD.org>2018-07-23 07:11:58 +0000
commit804771f5538f56e8ff1d556df7e7aa96e53a80f5 (patch)
treef562148cceb54310562ae53f691fcc3543a02946
parentafe7cf8749ae61fed65980d10817252a2c2b7677 (diff)
Notes
-rw-r--r--sys/net/if_epair.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/sys/net/if_epair.c b/sys/net/if_epair.c
index fc923dd97a1ff..7df837e6e6758 100644
--- a/sys/net/if_epair.c
+++ b/sys/net/if_epair.c
@@ -107,6 +107,7 @@ static int epair_clone_create(struct if_clone *, char *, size_t, caddr_t);
static int epair_clone_destroy(struct if_clone *, struct ifnet *);
static const char epairname[] = "epair";
+static unsigned int next_index = 0;
/* Netisr related definitions and sysctl. */
static struct netisr_handler epair_nh = {
@@ -843,12 +844,22 @@ epair_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params)
/*
* Calculate the etheraddr hashing the hostid and the
- * interface index. The result would be hopefully unique
+ * interface index. The result would be hopefully unique.
+ * Note that the "a" component of an epair instance may get moved
+ * to a different VNET after creation. In that case its index
+ * will be freed and the index can get reused by new epair instance.
+ * Make sure we do not create same etheraddr again.
*/
getcredhostid(curthread->td_ucred, (unsigned long *)&hostid);
if (hostid == 0)
arc4rand(&hostid, sizeof(hostid), 0);
- key[0] = (uint32_t)ifp->if_index;
+
+ if (ifp->if_index > next_index)
+ next_index = ifp->if_index;
+ else
+ next_index++;
+
+ key[0] = (uint32_t)next_index;
key[1] = (uint32_t)(hostid & 0xffffffff);
key[2] = (uint32_t)((hostid >> 32) & 0xfffffffff);
hash = jenkins_hash32(key, 3, 0);