Skip to content

Commit

Permalink
Merge pull request FRRouting#17468 from opensourcerouting/msdp-tweaks
Browse files Browse the repository at this point in the history
pimd: two small improvements
  • Loading branch information
Jafaral authored Nov 21, 2024
2 parents bca9911 + 1e0629f commit 8884f42
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
15 changes: 1 addition & 14 deletions pimd/pim_msdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,16 +1012,6 @@ void pim_msdp_peer_pkt_txed(struct pim_msdp_peer *mp)
}
}

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 */
}

/* 11.2.A1: create a new peer and transition state to listen or connecting */
struct pim_msdp_peer *pim_msdp_peer_add(struct pim_instance *pim,
const struct in_addr *peer,
Expand All @@ -1037,11 +1027,9 @@ struct pim_msdp_peer *pim_msdp_peer_add(struct pim_instance *pim,
mp->pim = pim;
mp->peer = *peer;
pim_inet4_dump("<peer?>", mp->peer, mp->key_str, sizeof(mp->key_str));
pim_msdp_addr2su(&mp->su_peer, mp->peer);
mp->local = *local;
/* XXX: originator_id setting needs to move to the mesh group */
pim->msdp.originator_id = *local;
pim_msdp_addr2su(&mp->su_local, mp->local);
if (mesh_group_name)
mp->mesh_group_name =
XSTRDUP(MTYPE_PIM_MSDP_MG_NAME, mesh_group_name);
Expand Down Expand Up @@ -1078,8 +1066,7 @@ struct pim_msdp_peer *pim_msdp_peer_add(struct pim_instance *pim,
return mp;
}

struct pim_msdp_peer *pim_msdp_peer_find(struct pim_instance *pim,
struct in_addr peer_addr)
struct pim_msdp_peer *pim_msdp_peer_find(const struct pim_instance *pim, struct in_addr peer_addr)
{
struct pim_msdp_peer lookup;

Expand Down
6 changes: 1 addition & 5 deletions pimd/pim_msdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ struct pim_msdp_peer {
enum pim_msdp_peer_state state;
enum pim_msdp_peer_flags flags;

/* TCP socket info */
union sockunion su_local;
union sockunion su_peer;
int fd;

/* protocol timers */
Expand Down Expand Up @@ -238,8 +235,7 @@ void pim_msdp_init(struct pim_instance *pim, struct event_loop *master);
void pim_msdp_exit(struct pim_instance *pim);
char *pim_msdp_state_dump(enum pim_msdp_peer_state state, char *buf,
int buf_size);
struct pim_msdp_peer *pim_msdp_peer_find(struct pim_instance *pim,
struct in_addr peer_addr);
struct pim_msdp_peer *pim_msdp_peer_find(const struct pim_instance *pim, struct in_addr peer_addr);
void pim_msdp_peer_established(struct pim_msdp_peer *mp);
void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer *mp);
void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state);
Expand Down
29 changes: 21 additions & 8 deletions pimd/pim_msdp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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));
}

0 comments on commit 8884f42

Please sign in to comment.