Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bfd remove control socket #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 6 additions & 66 deletions bfdd/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,8 @@ void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer,

struct bfd_session *bs_peer_find(struct bfd_peer_cfg *bpc)
{
struct bfd_session *bs;
struct peer_label *pl;
struct bfd_key key;

/* Try to find label first. */
if (bpc->bpc_has_label) {
pl = pl_find(bpc->bpc_label);
if (pl != NULL) {
bs = pl->pl_bs;
return bs;
}
}

/* Otherwise fallback to peer/local hash lookup. */
gen_bfd_key(&key, &bpc->bpc_peer, &bpc->bpc_local, bpc->bpc_mhop,
bpc->bpc_localif, bpc->bpc_vrfname);
Expand Down Expand Up @@ -328,7 +317,6 @@ int bfd_session_enable(struct bfd_session *bs)

/* Attempt to use data plane. */
if (bglobal.bg_use_dplane && bfd_dplane_add_session(bs) == 0) {
control_notify_config(BCM_NOTIFY_CONFIG_ADD, bs);
return 0;
}

Expand Down Expand Up @@ -502,7 +490,7 @@ void ptm_bfd_sess_up(struct bfd_session *bfd)
/* Start sending control packets with poll bit immediately. */
ptm_bfd_snd(bfd, 0);

control_notify(bfd, bfd->ses_state);
ptm_bfd_notify(bfd, bfd->ses_state);

if (old_state != bfd->ses_state) {
bfd->stats.session_up++;
Expand Down Expand Up @@ -538,7 +526,7 @@ void ptm_bfd_sess_dn(struct bfd_session *bfd, uint8_t diag)

/* only signal clients when going from up->down state */
if (old_state == PTM_BFD_UP)
control_notify(bfd, PTM_BFD_DOWN);
ptm_bfd_notify(bfd, PTM_BFD_DOWN);

/* Stop echo packet transmission if they are active */
if (CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
Expand Down Expand Up @@ -690,38 +678,6 @@ struct bfd_session *bfd_session_new(void)
return bs;
}

int bfd_session_update_label(struct bfd_session *bs, const char *nlabel)
{
/* New label treatment:
* - Check if the label is taken;
* - Try to allocate the memory for it and register;
*/
if (bs->pl == NULL) {
if (pl_find(nlabel) != NULL) {
/* Someone is already using it. */
return -1;
}

pl_new(nlabel, bs);

return 0;
}

/*
* Test label change consistency:
* - Do nothing if it's the same label;
* - Check if the future label is already taken;
* - Change label;
*/
if (strcmp(nlabel, bs->pl->pl_label) == 0)
return -1;
if (pl_find(nlabel) != NULL)
return -1;

strlcpy(bs->pl->pl_label, nlabel, sizeof(bs->pl->pl_label));
return 0;
}

static void _bfd_session_update(struct bfd_session *bs,
struct bfd_peer_cfg *bpc)
{
Expand Down Expand Up @@ -750,9 +706,6 @@ static void _bfd_session_update(struct bfd_session *bs,
bs->peer_profile.min_echo_tx = bs->timers.desired_min_echo_tx;
}

if (bpc->bpc_has_label)
bfd_session_update_label(bs, bpc->bpc_label);

if (bpc->bpc_cbit)
SET_FLAG(bs->flags, BFD_SESS_FLAG_CBIT);
else
Expand Down Expand Up @@ -792,8 +745,6 @@ static int bfd_session_update(struct bfd_session *bs, struct bfd_peer_cfg *bpc)

_bfd_session_update(bs, bpc);

control_notify_config(BCM_NOTIFY_CONFIG_UPDATE, bs);

return 0;
}

Expand All @@ -819,8 +770,6 @@ void bfd_session_free(struct bfd_session *bs)
if (bso != NULL)
bs_observer_del(bso);

pl_free(bs->pl);

XFREE(MTYPE_BFDD_PROFILE, bs->profile_name);
XFREE(MTYPE_BFDD_CONFIG, bs);
}
Expand Down Expand Up @@ -917,8 +866,6 @@ struct bfd_session *bs_registrate(struct bfd_session *bfd)
if (bglobal.debug_peer_event)
zlog_debug("session-new: %s", bs_to_string(bfd));

control_notify_config(BCM_NOTIFY_CONFIG_ADD, bfd);

return bfd;
}

Expand All @@ -941,8 +888,6 @@ int ptm_bfd_sess_del(struct bfd_peer_cfg *bpc)
if (bglobal.debug_peer_event)
zlog_debug("%s: %s", __func__, bs_to_string(bs));

control_notify_config(BCM_NOTIFY_CONFIG_DELETE, bs);

bfd_session_free(bs);

return 0;
Expand Down Expand Up @@ -1167,8 +1112,6 @@ void bs_final_handler(struct bfd_session *bs)
* for lost control packets.
*/
if (bs->demand_mode) {
/* Notify watchers about changed timers. */
control_notify_config(BCM_NOTIFY_CONFIG_UPDATE, bs);
return;
}

Expand All @@ -1189,9 +1132,6 @@ void bs_final_handler(struct bfd_session *bs)

/* Apply new transmission timer immediately. */
ptm_bfd_start_xmt_timer(bs, false);

/* Notify watchers about changed timers. */
control_notify_config(BCM_NOTIFY_CONFIG_UPDATE, bs);
}

void bs_set_slow_timers(struct bfd_session *bs)
Expand Down Expand Up @@ -1261,7 +1201,7 @@ void bfd_set_shutdown(struct bfd_session *bs, bool shutdown)
if (bs->bdc) {
bs->ses_state = PTM_BFD_ADM_DOWN;
bfd_dplane_update_session(bs);
control_notify(bs, bs->ses_state);
ptm_bfd_notify(bs, bs->ses_state);
return;
}

Expand All @@ -1273,7 +1213,7 @@ void bfd_set_shutdown(struct bfd_session *bs, bool shutdown)

/* Change and notify state change. */
bs->ses_state = PTM_BFD_ADM_DOWN;
control_notify(bs, bs->ses_state);
ptm_bfd_notify(bs, bs->ses_state);

/* Don't try to send packets with a disabled session. */
if (bs->sock != -1)
Expand All @@ -1289,13 +1229,13 @@ void bfd_set_shutdown(struct bfd_session *bs, bool shutdown)
if (bs->bdc) {
bs->ses_state = PTM_BFD_DOWN;
bfd_dplane_update_session(bs);
control_notify(bs, bs->ses_state);
ptm_bfd_notify(bs, bs->ses_state);
return;
}

/* Change and notify state change. */
bs->ses_state = PTM_BFD_DOWN;
control_notify(bs, bs->ses_state);
ptm_bfd_notify(bs, bs->ses_state);

/* Enable timers if non passive, otherwise stop them. */
if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_PASSIVE)) {
Expand Down
158 changes: 59 additions & 99 deletions bfdd/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,73 @@
#include "lib/queue.h"
#include "lib/vrf.h"

#include "bfdctl.h"

#ifdef BFD_DEBUG
#define BFDD_JSON_CONV_OPTIONS (JSON_C_TO_STRING_PRETTY)
#else
#define BFDD_JSON_CONV_OPTIONS (0)
#endif

#ifndef MAXNAMELEN
#define MAXNAMELEN 32
#endif

#define BPC_DEF_DETECTMULTIPLIER 3
#define BPC_DEF_RECEIVEINTERVAL 300 /* milliseconds */
#define BPC_DEF_TRANSMITINTERVAL 300 /* milliseconds */
#define BPC_DEF_ECHORECEIVEINTERVAL 50 /* milliseconds */
#define BPC_DEF_ECHOTRANSMITINTERVAL 50 /* milliseconds */

DECLARE_MGROUP(BFDD);
DECLARE_MTYPE(BFDD_CONTROL);
DECLARE_MTYPE(BFDD_NOTIFICATION);
DECLARE_MTYPE(BFDD_CLIENT);
DECLARE_MTYPE(BFDD_CLIENT_NOTIFICATION);

struct sockaddr_any {
union {
struct sockaddr_in sa_sin;
struct sockaddr_in6 sa_sin6;
};
};

struct bfd_peer_cfg {
bool bpc_mhop;
bool bpc_ipv4;
struct sockaddr_any bpc_peer;
struct sockaddr_any bpc_local;

bool bpc_has_localif;
char bpc_localif[MAXNAMELEN + 1];

bool bpc_has_vrfname;
char bpc_vrfname[MAXNAMELEN + 1];

bool bpc_has_detectmultiplier;
uint8_t bpc_detectmultiplier;

bool bpc_has_recvinterval;
uint64_t bpc_recvinterval;

bool bpc_has_txinterval;
uint64_t bpc_txinterval;

#define BFDD_SOCK_NAME "%s/bfdd.sock", frr_runstatedir
bool bpc_has_echorecvinterval;
uint64_t bpc_echorecvinterval;

bool bpc_has_echotxinterval;
uint64_t bpc_echotxinterval;

bool bpc_has_minimum_ttl;
uint8_t bpc_minimum_ttl;

bool bpc_echo;
bool bpc_createonly;
bool bpc_shutdown;

bool bpc_cbit;
bool bpc_passive;

bool bpc_has_profile;
char bpc_profile[64];
};

/* bfd Authentication Type. */
#define BFD_AUTH_NULL 0
Expand Down Expand Up @@ -246,9 +300,6 @@ struct bfd_profile {
/** Profile list type. */
TAILQ_HEAD(bfdproflist, bfd_profile);

/* bfd_session shortcut label forwarding. */
struct peer_label;

struct bfd_config_timers {
uint32_t desired_min_tx;
uint32_t required_min_rx;
Expand Down Expand Up @@ -326,14 +377,6 @@ struct bfd_session {
uint64_t rtt[BFD_RTT_SAMPLE]; /* RRT in usec for echo to be looped */
};

struct peer_label {
TAILQ_ENTRY(peer_label) pl_entry;

struct bfd_session *pl_bs;
char pl_label[MAXNAMELEN];
};
TAILQ_HEAD(pllist, peer_label);

struct bfd_diag_str_list {
const char *str;
int type;
Expand Down Expand Up @@ -385,64 +428,6 @@ TAILQ_HEAD(obslist, bfd_session_observer);
#define BFD_DEF_ECHO_PORT 3785
#define BFD_DEF_MHOP_DEST_PORT 4784

/*
* control.c
*
* Daemon control code to speak with local consumers.
*/

/* See 'bfdctrl.h' for client protocol definitions. */

struct bfd_control_buffer {
size_t bcb_left;
size_t bcb_pos;
union {
struct bfd_control_msg *bcb_bcm;
uint8_t *bcb_buf;
};
};

struct bfd_control_queue {
TAILQ_ENTRY(bfd_control_queue) bcq_entry;

struct bfd_control_buffer bcq_bcb;
};
TAILQ_HEAD(bcqueue, bfd_control_queue);

struct bfd_notify_peer {
TAILQ_ENTRY(bfd_notify_peer) bnp_entry;

struct bfd_session *bnp_bs;
};
TAILQ_HEAD(bnplist, bfd_notify_peer);

struct bfd_control_socket {
TAILQ_ENTRY(bfd_control_socket) bcs_entry;

int bcs_sd;
struct event *bcs_ev;
struct event *bcs_outev;
struct bcqueue bcs_bcqueue;

/* Notification data */
uint64_t bcs_notify;
struct bnplist bcs_bnplist;

enum bc_msg_version bcs_version;
enum bc_msg_type bcs_type;

/* Message buffering */
struct bfd_control_buffer bcs_bin;
struct bfd_control_buffer *bcs_bout;
};
TAILQ_HEAD(bcslist, bfd_control_socket);

int control_init(const char *path);
void control_shutdown(void);
int control_notify(struct bfd_session *bs, uint8_t notify_state);
int control_notify_config(const char *op, struct bfd_session *bs);
void control_accept(struct event *t);


/*
* bfdd.c
Expand All @@ -468,9 +453,6 @@ TAILQ_HEAD(dplane_queue, bfd_dplane_ctx);
struct bfd_global {
int bg_csock;
struct event *bg_csockev;
struct bcslist bg_bcslist;

struct pllist bg_pllist;

struct obslist bg_obslist;

Expand Down Expand Up @@ -516,27 +498,6 @@ extern const struct bfd_state_str_list state_list[];
void socket_close(int *s);


/*
* config.c
*
* Contains the code related with loading/reloading configuration.
*/
int parse_config(const char *fname);
int config_request_add(const char *jsonstr);
int config_request_del(const char *jsonstr);
char *config_response(const char *status, const char *error);
char *config_notify(struct bfd_session *bs);
char *config_notify_config(const char *op, struct bfd_session *bs);

typedef int (*bpc_handle)(struct bfd_peer_cfg *, void *arg);
int config_notify_request(struct bfd_control_socket *bcs, const char *jsonstr,
bpc_handle bh);

struct peer_label *pl_new(const char *label, struct bfd_session *bs);
struct peer_label *pl_find(const char *label);
void pl_free(struct peer_label *pl);


/*
* logging - alias to zebra log
*/
Expand Down Expand Up @@ -621,7 +582,6 @@ struct bfd_session *ptm_bfd_sess_find(struct bfd_pkt *cp,
bool is_mhop);

struct bfd_session *bs_peer_find(struct bfd_peer_cfg *bpc);
int bfd_session_update_label(struct bfd_session *bs, const char *nlabel);
void bfd_set_polling(struct bfd_session *bs);
void bs_state_handler(struct bfd_session *bs, int nstate);
void bs_echo_timer_handler(struct bfd_session *bs);
Expand Down
Loading
Loading