Message ID | 20200224235901.304311-2-ndev@hwipl.net |
---|---|
State | Changes Requested |
Delegated to: | David Miller |
Headers | show |
Series | net/smc: improve peer ID in CLC decline | expand |
On 25/02/2020 00:59, Hans Wippel wrote: > This patch initializes the peer ID to a random instance ID and a zero > MAC address. If a RoCE device is in the host, the MAC address part of > the peer ID is overwritten with the respective address. Also, a function > for checking if the peer ID is valid is added. A peer ID is considered > valid if the MAC address part contains a non-zero MAC address. > > Signed-off-by: Hans Wippel <ndev@hwipl.net> > --- > net/smc/smc_ib.c | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) > > diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c > index 6756bd5a3fe4..3444de27fecd 100644 > --- a/net/smc/smc_ib.c > +++ b/net/smc/smc_ib.c > @@ -37,11 +37,7 @@ struct smc_ib_devices smc_ib_devices = { /* smc-registered ib devices */ > .list = LIST_HEAD_INIT(smc_ib_devices.list), > }; > > -#define SMC_LOCAL_SYSTEMID_RESET "%%%%%%%" > - > -u8 local_systemid[SMC_SYSTEMID_LEN] = SMC_LOCAL_SYSTEMID_RESET; /* unique system > - * identifier > - */ > +u8 local_systemid[SMC_SYSTEMID_LEN]; /* unique system identifier */ > > static int smc_ib_modify_qp_init(struct smc_link *lnk) > { > @@ -168,6 +164,15 @@ static inline void smc_ib_define_local_systemid(struct smc_ib_device *smcibdev, > { > memcpy(&local_systemid[2], &smcibdev->mac[ibport - 1], > sizeof(smcibdev->mac[ibport - 1])); > +} > + > +bool smc_ib_is_valid_local_systemid(void) You introduce a non-static but its used only from this module. > +{ > + return !is_zero_ether_addr(&local_systemid[2]); > +} > + > +static void smc_ib_init_local_systemid(void) > +{ > get_random_bytes(&local_systemid[0], 2); > } > > @@ -224,8 +229,7 @@ static int smc_ib_remember_port_attr(struct smc_ib_device *smcibdev, u8 ibport) > rc = smc_ib_fill_mac(smcibdev, ibport); > if (rc) > goto out; > - if (!strncmp(local_systemid, SMC_LOCAL_SYSTEMID_RESET, > - sizeof(local_systemid)) && > + if (!smc_ib_is_valid_local_systemid() && > smc_ib_port_active(smcibdev, ibport)) > /* create unique system identifier */ > smc_ib_define_local_systemid(smcibdev, ibport); > @@ -605,6 +609,7 @@ static struct ib_client smc_ib_client = { > > int __init smc_ib_register_client(void) > { > + smc_ib_init_local_systemid(); > return ib_register_client(&smc_ib_client); > } > >
diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c index 6756bd5a3fe4..3444de27fecd 100644 --- a/net/smc/smc_ib.c +++ b/net/smc/smc_ib.c @@ -37,11 +37,7 @@ struct smc_ib_devices smc_ib_devices = { /* smc-registered ib devices */ .list = LIST_HEAD_INIT(smc_ib_devices.list), }; -#define SMC_LOCAL_SYSTEMID_RESET "%%%%%%%" - -u8 local_systemid[SMC_SYSTEMID_LEN] = SMC_LOCAL_SYSTEMID_RESET; /* unique system - * identifier - */ +u8 local_systemid[SMC_SYSTEMID_LEN]; /* unique system identifier */ static int smc_ib_modify_qp_init(struct smc_link *lnk) { @@ -168,6 +164,15 @@ static inline void smc_ib_define_local_systemid(struct smc_ib_device *smcibdev, { memcpy(&local_systemid[2], &smcibdev->mac[ibport - 1], sizeof(smcibdev->mac[ibport - 1])); +} + +bool smc_ib_is_valid_local_systemid(void) +{ + return !is_zero_ether_addr(&local_systemid[2]); +} + +static void smc_ib_init_local_systemid(void) +{ get_random_bytes(&local_systemid[0], 2); } @@ -224,8 +229,7 @@ static int smc_ib_remember_port_attr(struct smc_ib_device *smcibdev, u8 ibport) rc = smc_ib_fill_mac(smcibdev, ibport); if (rc) goto out; - if (!strncmp(local_systemid, SMC_LOCAL_SYSTEMID_RESET, - sizeof(local_systemid)) && + if (!smc_ib_is_valid_local_systemid() && smc_ib_port_active(smcibdev, ibport)) /* create unique system identifier */ smc_ib_define_local_systemid(smcibdev, ibport); @@ -605,6 +609,7 @@ static struct ib_client smc_ib_client = { int __init smc_ib_register_client(void) { + smc_ib_init_local_systemid(); return ib_register_client(&smc_ib_client); }
This patch initializes the peer ID to a random instance ID and a zero MAC address. If a RoCE device is in the host, the MAC address part of the peer ID is overwritten with the respective address. Also, a function for checking if the peer ID is valid is added. A peer ID is considered valid if the MAC address part contains a non-zero MAC address. Signed-off-by: Hans Wippel <ndev@hwipl.net> --- net/smc/smc_ib.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)