diff options
author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2022-05-27 22:15:46 +0200 |
---|---|---|
committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2024-11-20 16:06:00 +0100 |
commit | 8f829b2495f3dbfe33ffada7f6f7aaa6289dd3ce (patch) | |
tree | 94d197bf66fcc006729b999de9a77549c6d50798 /pimd/pim_msdp_socket.c | |
parent | Merge pull request #17156 from opensourcerouting/eradicate-strncpy (diff) | |
download | frr-8f829b2495f3dbfe33ffada7f6f7aaa6289dd3ce.tar.xz frr-8f829b2495f3dbfe33ffada7f6f7aaa6289dd3ce.zip |
pimd: remove temporary variables from MSDP peer
Remove from MSDP peer data structure two temporary variables
that should only be used when calling library functions.
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to '')
-rw-r--r-- | pimd/pim_msdp_socket.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/pimd/pim_msdp_socket.c b/pimd/pim_msdp_socket.c index 2fb0bb87c..b29993304 100644 --- a/pimd/pim_msdp_socket.c +++ b/pimd/pim_msdp_socket.c @@ -49,6 +49,16 @@ static void pim_msdp_update_sock_send_buffer_size(int fd) } } +static void pim_msdp_addr2su(union sockunion *su, struct in_addr addr) +{ + sockunion_init(su); + su->sin.sin_addr = addr; + su->sin.sin_family = AF_INET; +#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN + su->sin.sin_len = sizeof(struct sockaddr_in); +#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ +} + /** * Helper function to reduce code duplication. * @@ -64,7 +74,6 @@ static int _pim_msdp_sock_listen(const struct vrf *vrf, int rv; socklen_t socklen; struct sockaddr_in sin = {}; - union sockunion su_peer = {}; sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == -1) { @@ -117,7 +126,9 @@ static int _pim_msdp_sock_listen(const struct vrf *vrf, /* Set MD5 authentication. */ if (mp && mp->auth_key) { - su_peer = mp->su_peer; + union sockunion su_peer = {}; + + pim_msdp_addr2su(&su_peer, mp->peer); frr_with_privs (&pimd_privs) { sockopt_tcp_signature(sock, &su_peer, mp->auth_key); } @@ -349,6 +360,7 @@ int pim_msdp_sock_listen(struct pim_instance *pim) int pim_msdp_sock_connect(struct pim_msdp_peer *mp) { int rc; + union sockunion su_peer = {}, su_local = {}; if (PIM_DEBUG_MSDP_INTERNAL) { zlog_debug("MSDP peer %s attempt connect%s", mp->key_str, @@ -366,8 +378,11 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) pim_msdp_peer_stop_tcp_conn(mp, false /* chg_state */); } + pim_msdp_addr2su(&su_peer, mp->peer); + pim_msdp_addr2su(&su_local, mp->local); + /* Make socket for the peer. */ - mp->fd = sockunion_socket(&mp->su_peer); + mp->fd = sockunion_socket(&su_peer); if (mp->fd < 0) { flog_err_sys(EC_LIB_SOCKET, "pim_msdp_socket socket failure: %s", @@ -402,7 +417,7 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) sockopt_reuseport(mp->fd); /* source bind */ - rc = sockunion_bind(mp->fd, &mp->su_local, 0, &mp->su_local); + rc = sockunion_bind(mp->fd, &su_local, 0, &su_local); if (rc < 0) { flog_err_sys(EC_LIB_SOCKET, "pim_msdp_socket connect bind failure: %s", @@ -421,12 +436,10 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) /* Set authentication (if configured). */ if (mp->auth_key) { frr_with_privs (&pimd_privs) { - sockopt_tcp_signature(mp->fd, &mp->su_peer, - mp->auth_key); + sockopt_tcp_signature(mp->fd, &su_peer, mp->auth_key); } } /* Connect to the remote mp. */ - return (sockunion_connect(mp->fd, &mp->su_peer, - htons(PIM_MSDP_TCP_PORT), 0)); + return (sockunion_connect(mp->fd, &su_peer, htons(PIM_MSDP_TCP_PORT), 0)); } |