diff options
-rw-r--r-- | src/peer.c | 8 | ||||
-rw-r--r-- | src/peer_group.h | 14 | ||||
-rw-r--r-- | src/protocols/ec25519_fhmqvc/handshake.c | 2 |
3 files changed, 19 insertions, 5 deletions
@@ -126,25 +126,25 @@ void fastd_peer_exec_shell_command(const fastd_shell_command_t *command, const f /** Calls the on-up command */ static inline void on_up(const fastd_peer_t *peer, bool sync) { - const fastd_shell_command_t *on_up = container_of(fastd_peer_group_lookup_peer(peer, on_up.command), fastd_shell_command_t, command); + const fastd_shell_command_t *on_up = fastd_peer_group_lookup_peer_shell_command(peer, on_up); fastd_peer_exec_shell_command(on_up, peer, NULL, NULL, sync); } /** Calls the on-down command */ static inline void on_down(const fastd_peer_t *peer, bool sync) { - const fastd_shell_command_t *on_down = container_of(fastd_peer_group_lookup_peer(peer, on_down.command), fastd_shell_command_t, command); + const fastd_shell_command_t *on_down = fastd_peer_group_lookup_peer_shell_command(peer, on_down); fastd_peer_exec_shell_command(on_down, peer, NULL, NULL, sync); } /** Executes the on-establish command for a peer */ static inline void on_establish(const fastd_peer_t *peer) { - const fastd_shell_command_t *on_establish = container_of(fastd_peer_group_lookup_peer(peer, on_establish.command), fastd_shell_command_t, command); + const fastd_shell_command_t *on_establish = fastd_peer_group_lookup_peer_shell_command(peer, on_establish); fastd_peer_exec_shell_command(on_establish, peer, &peer->local_address, &peer->address, false); } /** Executes the on-disestablish command for a peer */ static inline void on_disestablish(const fastd_peer_t *peer) { - const fastd_shell_command_t *on_disestablish = container_of(fastd_peer_group_lookup_peer(peer, on_disestablish.command), fastd_shell_command_t, command); + const fastd_shell_command_t *on_disestablish = fastd_peer_group_lookup_peer_shell_command(peer, on_disestablish); fastd_peer_exec_shell_command(on_disestablish, peer, &peer->local_address, &peer->address, false); } diff --git a/src/peer_group.h b/src/peer_group.h index edba73e..69974a4 100644 --- a/src/peer_group.h +++ b/src/peer_group.h @@ -95,3 +95,17 @@ struct fastd_peer_group { const fastd_peer_t *_peer = (peer); \ _peer ? fastd_peer_group_lookup(_peer->group, attr) : &conf.peer_group->attr; \ }) + +/** + Looks up an shell command attribute in the peer group tree, for a given peer + + Returns a pointer to the attribute, going up the group tree to the first group + where the attribute is not NULL if such a group exists. Uses the default group + if no peer is given. + + @param peer the peer + @param attr the name of the shell command member + + \hideinitializer + */ +#define fastd_peer_group_lookup_peer_shell_command(peer, attr) container_of(fastd_peer_group_lookup_peer(peer, attr.command), fastd_shell_command_t, command) diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c index cebf25e..ee26892 100644 --- a/src/protocols/ec25519_fhmqvc/handshake.c +++ b/src/protocols/ec25519_fhmqvc/handshake.c @@ -513,7 +513,7 @@ void fastd_protocol_ec25519_fhmqvc_handshake_init(fastd_socket_t *sock, const fa fastd_handshake_add(&buffer, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES, &ctx.protocol_state->handshake_key.key.public); if (!peer || !fastd_peer_is_established(peer)) { - const fastd_shell_command_t *on_connect = container_of(fastd_peer_group_lookup_peer(peer, on_connect.command), fastd_shell_command_t, command); + const fastd_shell_command_t *on_connect = fastd_peer_group_lookup_peer_shell_command(peer, on_connect); fastd_peer_exec_shell_command(on_connect, peer, (local_addr && local_addr->sa.sa_family) ? local_addr : sock->bound_addr, remote_addr, false); } |