Vitaly Demyanec
2009-May-21 12:03 UTC
[Bridge] [PATCH] rstpd: sizeof mismatch for some setups
This patch is against rstpd v.0.21 (get it here: https://lists.linux-foundation.org/pipermail/bridge/2009-February/006178.html). BTW, it seems there are 2 rstpd forks, one is v.0.21 and is maintained by Srinivas, while the other uses rstplib, is v.0.16 and is maintained by Stephen (here: http://git.kernel.org/?p=linux/kernel/git/shemminger/rstp.git;a=summary) I am pretty confused with this divergence, which should one use to start from? (personally I selected Srinivas' version as it seems to be more up-to-date). Description: For some setups (e.g. mine) sizeof(STP_MacAddress) != 6, which causes compiler error (thanks to the CMP macro, it's really useful) Signed-off-by: Vitaly Demyanec <vitas at nppfactor.kiev.ua> --- --- a/rstp.c 2009-05-21 13:01:09.000000000 +0300 +++ b/rstp.c 2009-05-21 13:06:08.000000000 +0300 @@ -2600,9 +2600,9 @@ } if (cfg->set_bridge_address && - CMP(BridgeIdentifier.bridge_address, !=, cfg->bridge_address)) { + CMP(BridgeIdentifier.bridge_address, !=, cfg->bridge_address.addr)) { - CPY(BridgeIdentifier.bridge_address, cfg->bridge_address); + CPY(BridgeIdentifier.bridge_address, cfg->bridge_address.addr); changed = TRUE; init = TRUE; -- With Best Regards, Vitaly Demyanec Head engineer Factor-SPE Kiev, Ukraine tel/fax: +380(44)249-21-63
Vitaly Demyanec
2009-May-22 13:20 UTC
[Bridge] [PATCH] rstpd: sizeof mismatch + macro enhancement
This patch is against rstpd v.0.21 (get it here: https://lists.linux-foundation.org/pipermail/bridge/2009-February/006178.html). Description: 1. For some setups (e.g. mine) sizeof(struct sockaddr_un) != sizeof((sa)->sun_family) + sizeof((sa)->sun_path) , which leads to incomplete clean-up in set_socket_address macro, which in turn leads to different socket addresses in rstpd and rstpctl. 2. We should avoid possible side-effects multiplication in the (sa) (e.g. when this macro is called like this: set_socket_address(++sa_ptr, str[i])) by the use of temporary variable inside the macro. Signed-off-by: Vitaly Demyanec <vitas at nppfactor.kiev.ua> --- diff -ur a/ctl_socket.h b/ctl_socket.h --- a/ctl_socket.h 2009-05-22 15:34:00.000000000 +0300 +++ b/ctl_socket.h 2009-05-22 16:17:47.000000000 +0300 @@ -47,10 +47,11 @@ #define set_socket_address(sa, string) \ do {\ - (sa)->sun_family = AF_UNIX; \ - memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \ - strcpy((sa)->sun_path + 1, (string)); \ - } while (0) + struct sockaddr_un * tmp_sa = (sa); \ + memset(tmp_sa, 0, sizeof(*tmp_sa)); \ + tmp_sa->sun_family = AF_UNIX; \ + strcpy(tmp_sa->sun_path + 1, (string)); \ +} while (0) #define RSTP_SERVER_SOCK_NAME ".rstp_server" -- With Best Regards, Vitaly Demyanec Head engineer Factor-SPE Kiev, Ukraine tel/fax: +380(44)249-21-63