diff options
| author | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:03:14 +0200 | 
|---|---|---|
| committer | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:04:07 +0200 | 
| commit | d62a17aedeb0eebdba98238874bb13d62c48dbf9 (patch) | |
| tree | 3b319b1d61c8b85b4d1f06adf8b844bb8a9b5107 /pimd/pim_bfd.c | |
| parent | 888ac268a0077fc9ebd1218cec6ae472af0bfc40 (diff) | |
*: reindentreindent-master-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'pimd/pim_bfd.c')
| -rw-r--r-- | pimd/pim_bfd.c | 474 | 
1 files changed, 224 insertions, 250 deletions
diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c index af8a8e2c52..e4c50a18be 100644 --- a/pimd/pim_bfd.c +++ b/pimd/pim_bfd.c @@ -38,101 +38,94 @@  /*   * pim_bfd_write_config - Write the interface BFD configuration.   */ -void -pim_bfd_write_config (struct vty *vty, struct interface *ifp) +void pim_bfd_write_config(struct vty *vty, struct interface *ifp)  { -  struct pim_interface *pim_ifp = ifp->info; -  struct bfd_info *bfd_info = NULL; - -  if (!pim_ifp) -    return; - -  bfd_info = (struct bfd_info *) pim_ifp->bfd_info; -  if (!bfd_info) -    return; - -  if (CHECK_FLAG (bfd_info->flags, BFD_FLAG_PARAM_CFG)) -    vty_out (vty, " ip pim bfd %d %d %d\n", -             bfd_info->detect_mult, bfd_info->required_min_rx, -             bfd_info->desired_min_tx); -  else -    vty_out (vty, " ip pim bfd\n"); +	struct pim_interface *pim_ifp = ifp->info; +	struct bfd_info *bfd_info = NULL; + +	if (!pim_ifp) +		return; + +	bfd_info = (struct bfd_info *)pim_ifp->bfd_info; +	if (!bfd_info) +		return; + +	if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG)) +		vty_out(vty, " ip pim bfd %d %d %d\n", bfd_info->detect_mult, +			bfd_info->required_min_rx, bfd_info->desired_min_tx); +	else +		vty_out(vty, " ip pim bfd\n");  }  /*   * pim_bfd_show_info - Show BFD info structure   */ -void -pim_bfd_show_info (struct vty *vty, void *bfd_info, json_object * json_obj, -                   u_char use_json, int param_only) +void pim_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj, +		       u_char use_json, int param_only)  { -  if (param_only) -    bfd_show_param (vty, (struct bfd_info *) bfd_info, 1, 0, use_json, -                    json_obj); -  else -    bfd_show_info (vty, (struct bfd_info *) bfd_info, 0, 1, use_json, -                   json_obj); +	if (param_only) +		bfd_show_param(vty, (struct bfd_info *)bfd_info, 1, 0, use_json, +			       json_obj); +	else +		bfd_show_info(vty, (struct bfd_info *)bfd_info, 0, 1, use_json, +			      json_obj);  }  /*   * pim_bfd_info_nbr_create - Create/update BFD information for a neighbor.   */ -void -pim_bfd_info_nbr_create (struct pim_interface *pim_ifp, -                         struct pim_neighbor *neigh) +void pim_bfd_info_nbr_create(struct pim_interface *pim_ifp, +			     struct pim_neighbor *neigh)  { -  struct bfd_info *nbr_bfd_info = NULL; +	struct bfd_info *nbr_bfd_info = NULL; -  /* Check if Pim Interface BFD is enabled */ -  if (!pim_ifp || !pim_ifp->bfd_info) -    return; +	/* Check if Pim Interface BFD is enabled */ +	if (!pim_ifp || !pim_ifp->bfd_info) +		return; -  if (!neigh->bfd_info) -    neigh->bfd_info = bfd_info_create (); +	if (!neigh->bfd_info) +		neigh->bfd_info = bfd_info_create(); -  if (!neigh->bfd_info) -    return; +	if (!neigh->bfd_info) +		return; -  nbr_bfd_info = (struct bfd_info *) neigh->bfd_info; -  nbr_bfd_info->detect_mult = pim_ifp->bfd_info->detect_mult; -  nbr_bfd_info->desired_min_tx = pim_ifp->bfd_info->desired_min_tx; -  nbr_bfd_info->required_min_rx = pim_ifp->bfd_info->required_min_rx; +	nbr_bfd_info = (struct bfd_info *)neigh->bfd_info; +	nbr_bfd_info->detect_mult = pim_ifp->bfd_info->detect_mult; +	nbr_bfd_info->desired_min_tx = pim_ifp->bfd_info->desired_min_tx; +	nbr_bfd_info->required_min_rx = pim_ifp->bfd_info->required_min_rx;  }  /*   * pim_bfd_info_free - Free BFD info structure   */ -void -pim_bfd_info_free (void **bfd_info) +void pim_bfd_info_free(void **bfd_info)  { -  bfd_info_free ((struct bfd_info **) bfd_info); +	bfd_info_free((struct bfd_info **)bfd_info);  } -static void -pim_bfd_reg_dereg_nbr (struct pim_neighbor *nbr, int command) +static void pim_bfd_reg_dereg_nbr(struct pim_neighbor *nbr, int command)  { -  struct pim_interface *pim_ifp = NULL; -  struct bfd_info *bfd_info = NULL; -  struct zclient *zclient = NULL; - -  zclient = pim_zebra_zclient_get (); - -  if (!nbr) -    return; -  pim_ifp = nbr->interface->info; -  bfd_info = (struct bfd_info *) pim_ifp->bfd_info; -  if (!bfd_info) -    return; -  if (PIM_DEBUG_PIM_TRACE) -    { -      char str[INET_ADDRSTRLEN]; -      pim_inet4_dump ("<bfd_nbr?>", nbr->source_addr, str, sizeof (str)); -      zlog_debug ("%s Nbr %s %s with BFD", __PRETTY_FUNCTION__, str, -              bfd_get_command_dbg_str (command)); -    } -  bfd_peer_sendmsg (zclient, bfd_info, AF_INET, -                    &nbr->source_addr, NULL, nbr->interface->name, -                    0, 0, command, 0, VRF_DEFAULT); +	struct pim_interface *pim_ifp = NULL; +	struct bfd_info *bfd_info = NULL; +	struct zclient *zclient = NULL; + +	zclient = pim_zebra_zclient_get(); + +	if (!nbr) +		return; +	pim_ifp = nbr->interface->info; +	bfd_info = (struct bfd_info *)pim_ifp->bfd_info; +	if (!bfd_info) +		return; +	if (PIM_DEBUG_PIM_TRACE) { +		char str[INET_ADDRSTRLEN]; +		pim_inet4_dump("<bfd_nbr?>", nbr->source_addr, str, +			       sizeof(str)); +		zlog_debug("%s Nbr %s %s with BFD", __PRETTY_FUNCTION__, str, +			   bfd_get_command_dbg_str(command)); +	} +	bfd_peer_sendmsg(zclient, bfd_info, AF_INET, &nbr->source_addr, NULL, +			 nbr->interface->name, 0, 0, command, 0, VRF_DEFAULT);  }  /* @@ -141,75 +134,68 @@ pim_bfd_reg_dereg_nbr (struct pim_neighbor *nbr, int command)   *                              zebra for starting/stopping the monitoring of   *                              the neighbor rechahability.   */ -int -pim_bfd_reg_dereg_all_nbr (struct interface *ifp, int command) +int pim_bfd_reg_dereg_all_nbr(struct interface *ifp, int command)  { -  struct pim_interface *pim_ifp = NULL; -  struct listnode *node = NULL; -  struct pim_neighbor *neigh = NULL; - -  pim_ifp = ifp->info; -  if (!pim_ifp) -    return -1; -  if (!pim_ifp->bfd_info) -    return -1; - -  for (ALL_LIST_ELEMENTS_RO (pim_ifp->pim_neighbor_list, node, neigh)) -    { -      if (command != ZEBRA_BFD_DEST_DEREGISTER) -        pim_bfd_info_nbr_create (pim_ifp, neigh); -      else -        bfd_info_free ((struct bfd_info **) &neigh->bfd_info); - -      pim_bfd_reg_dereg_nbr (neigh, command); -    } - -  return 0; +	struct pim_interface *pim_ifp = NULL; +	struct listnode *node = NULL; +	struct pim_neighbor *neigh = NULL; + +	pim_ifp = ifp->info; +	if (!pim_ifp) +		return -1; +	if (!pim_ifp->bfd_info) +		return -1; + +	for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) { +		if (command != ZEBRA_BFD_DEST_DEREGISTER) +			pim_bfd_info_nbr_create(pim_ifp, neigh); +		else +			bfd_info_free((struct bfd_info **)&neigh->bfd_info); + +		pim_bfd_reg_dereg_nbr(neigh, command); +	} + +	return 0;  }  /*   * pim_bfd_trigger_event - Neighbor is registered/deregistered with BFD when   *                          neighbor state is changed to/from 2way.   */ -void -pim_bfd_trigger_event (struct pim_interface *pim_ifp, struct pim_neighbor *nbr, uint8_t nbr_up) +void pim_bfd_trigger_event(struct pim_interface *pim_ifp, +			   struct pim_neighbor *nbr, uint8_t nbr_up)  { -  if (nbr_up) -    { -      pim_bfd_info_nbr_create (pim_ifp, nbr); -      pim_bfd_reg_dereg_nbr (nbr, ZEBRA_BFD_DEST_REGISTER); -    } -  else -    { -      pim_bfd_info_free ((void *)&nbr->bfd_info); -      pim_bfd_reg_dereg_nbr (nbr, ZEBRA_BFD_DEST_DEREGISTER); -    } +	if (nbr_up) { +		pim_bfd_info_nbr_create(pim_ifp, nbr); +		pim_bfd_reg_dereg_nbr(nbr, ZEBRA_BFD_DEST_REGISTER); +	} else { +		pim_bfd_info_free((void *)&nbr->bfd_info); +		pim_bfd_reg_dereg_nbr(nbr, ZEBRA_BFD_DEST_DEREGISTER); +	}  }  /*   * pim_bfd_if_param_set - Set the configured BFD paramter values for   *                         interface.   */ -void -pim_bfd_if_param_set (struct interface *ifp, u_int32_t min_rx, -                      u_int32_t min_tx, u_int8_t detect_mult, int defaults) +void pim_bfd_if_param_set(struct interface *ifp, u_int32_t min_rx, +			  u_int32_t min_tx, u_int8_t detect_mult, int defaults)  { -  struct pim_interface *pim_ifp = ifp->info; -  int command = 0; - -  if (!pim_ifp) -    return; -  bfd_set_param ((struct bfd_info **) &(pim_ifp->bfd_info), min_rx, min_tx, -                 detect_mult, defaults, &command); - -  if (pim_ifp->bfd_info) -    { -      if (PIM_DEBUG_PIM_TRACE) -        zlog_debug ("%s: interface %s has bfd_info", __PRETTY_FUNCTION__, -                    ifp->name); -    } -  if (command) -    pim_bfd_reg_dereg_all_nbr (ifp, command); +	struct pim_interface *pim_ifp = ifp->info; +	int command = 0; + +	if (!pim_ifp) +		return; +	bfd_set_param((struct bfd_info **)&(pim_ifp->bfd_info), min_rx, min_tx, +		      detect_mult, defaults, &command); + +	if (pim_ifp->bfd_info) { +		if (PIM_DEBUG_PIM_TRACE) +			zlog_debug("%s: interface %s has bfd_info", +				   __PRETTY_FUNCTION__, ifp->name); +	} +	if (command) +		pim_bfd_reg_dereg_all_nbr(ifp, command);  } @@ -219,145 +205,133 @@ pim_bfd_if_param_set (struct interface *ifp, u_int32_t min_rx,   *                                  connectivity if the BFD status changed to   *                                  down.   */ -static int -pim_bfd_interface_dest_update (int command, struct zclient *zclient, -                               zebra_size_t length, vrf_id_t vrf_id) +static int pim_bfd_interface_dest_update(int command, struct zclient *zclient, +					 zebra_size_t length, vrf_id_t vrf_id)  { -  struct interface *ifp = NULL; -  struct pim_interface *pim_ifp = NULL; -  struct prefix p; -  int status; -  char msg[100]; -  int old_status; -  struct bfd_info *bfd_info = NULL; -  struct timeval tv; -  struct listnode *neigh_node = NULL; -  struct listnode *neigh_nextnode = NULL; -  struct pim_neighbor *neigh = NULL; - -  ifp = bfd_get_peer_info (zclient->ibuf, &p, NULL, &status, vrf_id); - -  if ((ifp == NULL) || (p.family != AF_INET)) -    return 0; - -  pim_ifp = ifp->info; -  if (!pim_ifp) -    return 0; - -  if (!pim_ifp->bfd_info) -    { -      if (PIM_DEBUG_PIM_TRACE) -        zlog_debug ("%s: pim interface %s BFD is disabled ", __PRETTY_FUNCTION__, -                    ifp->name); -      return 0; -    } - -  if (PIM_DEBUG_PIM_TRACE) -    { -      char buf[PREFIX2STR_BUFFER]; -      prefix2str (&p, buf, sizeof (buf)); -      zlog_debug ("%s: interface %s bfd destination %s %s", -                  __PRETTY_FUNCTION__, ifp->name, buf, -                  bfd_get_status_str (status)); -    } - -  for (ALL_LIST_ELEMENTS (pim_ifp->pim_neighbor_list, neigh_node, -                          neigh_nextnode, neigh)) -    { -      /* Check neigh address matches with BFD address */ -      if (neigh->source_addr.s_addr != p.u.prefix4.s_addr) -        continue; - -      bfd_info = (struct bfd_info *) neigh->bfd_info; -      if (bfd_info->status == status) -        { -          if (PIM_DEBUG_PIM_TRACE) -            { -              char str[INET_ADDRSTRLEN]; -              pim_inet4_dump ("<nht_nbr?>", neigh->source_addr, str, -                              sizeof (str)); -              zlog_debug ("%s: bfd status is same for nbr %s", -                          __PRETTY_FUNCTION__, str); -            } -          continue; -        } -      old_status = bfd_info->status; -      bfd_info->status = status; -      monotime(&tv); -      bfd_info->last_update = tv.tv_sec; - -      if (PIM_DEBUG_PIM_TRACE) -        { -          zlog_debug ("%s: status %s old_status %s", __PRETTY_FUNCTION__, -                      bfd_get_status_str (status), -                      bfd_get_status_str (old_status)); -        } -      if ((status == BFD_STATUS_DOWN) && (old_status == BFD_STATUS_UP)) -        { -          snprintf (msg, sizeof (msg), "BFD Session Expired"); -          pim_neighbor_delete (ifp, neigh, msg); -        } -    } -  return 0; +	struct interface *ifp = NULL; +	struct pim_interface *pim_ifp = NULL; +	struct prefix p; +	int status; +	char msg[100]; +	int old_status; +	struct bfd_info *bfd_info = NULL; +	struct timeval tv; +	struct listnode *neigh_node = NULL; +	struct listnode *neigh_nextnode = NULL; +	struct pim_neighbor *neigh = NULL; + +	ifp = bfd_get_peer_info(zclient->ibuf, &p, NULL, &status, vrf_id); + +	if ((ifp == NULL) || (p.family != AF_INET)) +		return 0; + +	pim_ifp = ifp->info; +	if (!pim_ifp) +		return 0; + +	if (!pim_ifp->bfd_info) { +		if (PIM_DEBUG_PIM_TRACE) +			zlog_debug("%s: pim interface %s BFD is disabled ", +				   __PRETTY_FUNCTION__, ifp->name); +		return 0; +	} + +	if (PIM_DEBUG_PIM_TRACE) { +		char buf[PREFIX2STR_BUFFER]; +		prefix2str(&p, buf, sizeof(buf)); +		zlog_debug("%s: interface %s bfd destination %s %s", +			   __PRETTY_FUNCTION__, ifp->name, buf, +			   bfd_get_status_str(status)); +	} + +	for (ALL_LIST_ELEMENTS(pim_ifp->pim_neighbor_list, neigh_node, +			       neigh_nextnode, neigh)) { +		/* Check neigh address matches with BFD address */ +		if (neigh->source_addr.s_addr != p.u.prefix4.s_addr) +			continue; + +		bfd_info = (struct bfd_info *)neigh->bfd_info; +		if (bfd_info->status == status) { +			if (PIM_DEBUG_PIM_TRACE) { +				char str[INET_ADDRSTRLEN]; +				pim_inet4_dump("<nht_nbr?>", neigh->source_addr, +					       str, sizeof(str)); +				zlog_debug("%s: bfd status is same for nbr %s", +					   __PRETTY_FUNCTION__, str); +			} +			continue; +		} +		old_status = bfd_info->status; +		bfd_info->status = status; +		monotime(&tv); +		bfd_info->last_update = tv.tv_sec; + +		if (PIM_DEBUG_PIM_TRACE) { +			zlog_debug("%s: status %s old_status %s", +				   __PRETTY_FUNCTION__, +				   bfd_get_status_str(status), +				   bfd_get_status_str(old_status)); +		} +		if ((status == BFD_STATUS_DOWN) +		    && (old_status == BFD_STATUS_UP)) { +			snprintf(msg, sizeof(msg), "BFD Session Expired"); +			pim_neighbor_delete(ifp, neigh, msg); +		} +	} +	return 0;  }  /*   * pim_bfd_nbr_replay - Replay all the neighbors that have BFD enabled   *                       to zebra   */ -static int -pim_bfd_nbr_replay (int command, struct zclient *zclient, zebra_size_t length, -                    vrf_id_t vrf_id) +static int pim_bfd_nbr_replay(int command, struct zclient *zclient, +			      zebra_size_t length, vrf_id_t vrf_id)  { -  struct interface *ifp = NULL; -  struct pim_interface *pim_ifp = NULL; -  struct pim_neighbor *neigh = NULL; -  struct listnode *node; -  struct listnode *neigh_node; -  struct listnode *neigh_nextnode; - -  /* Send the client registration */ -  bfd_client_sendmsg (zclient, ZEBRA_BFD_CLIENT_REGISTER); - -  for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp)) -    { -      pim_ifp = ifp->info; - -      if (!pim_ifp) -        continue; - -      if (pim_ifp->pim_sock_fd < 0) -        continue; - -      for (ALL_LIST_ELEMENTS (pim_ifp->pim_neighbor_list, neigh_node, -                              neigh_nextnode, neigh)) -        { -          if (!neigh->bfd_info) -            continue; -          if (PIM_DEBUG_PIM_TRACE) -            { -              char str[INET_ADDRSTRLEN]; -              pim_inet4_dump ("<bfd_nbr?>", neigh->source_addr, str, -                              sizeof (str)); -              zlog_debug ("%s: Replaying Pim Neigh %s to BFD", -                          __PRETTY_FUNCTION__, str); -            } -          pim_bfd_reg_dereg_nbr (neigh, ZEBRA_BFD_DEST_UPDATE); - -        } -    } -  return 0; +	struct interface *ifp = NULL; +	struct pim_interface *pim_ifp = NULL; +	struct pim_neighbor *neigh = NULL; +	struct listnode *node; +	struct listnode *neigh_node; +	struct listnode *neigh_nextnode; + +	/* Send the client registration */ +	bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); + +	for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { +		pim_ifp = ifp->info; + +		if (!pim_ifp) +			continue; + +		if (pim_ifp->pim_sock_fd < 0) +			continue; + +		for (ALL_LIST_ELEMENTS(pim_ifp->pim_neighbor_list, neigh_node, +				       neigh_nextnode, neigh)) { +			if (!neigh->bfd_info) +				continue; +			if (PIM_DEBUG_PIM_TRACE) { +				char str[INET_ADDRSTRLEN]; +				pim_inet4_dump("<bfd_nbr?>", neigh->source_addr, +					       str, sizeof(str)); +				zlog_debug("%s: Replaying Pim Neigh %s to BFD", +					   __PRETTY_FUNCTION__, str); +			} +			pim_bfd_reg_dereg_nbr(neigh, ZEBRA_BFD_DEST_UPDATE); +		} +	} +	return 0;  } -void -pim_bfd_init (void) +void pim_bfd_init(void)  { -  struct zclient *zclient = NULL; +	struct zclient *zclient = NULL; -  zclient = pim_zebra_zclient_get (); +	zclient = pim_zebra_zclient_get(); -  bfd_gbl_init (); +	bfd_gbl_init(); -  zclient->interface_bfd_dest_update = pim_bfd_interface_dest_update; -  zclient->bfd_dest_replay = pim_bfd_nbr_replay; +	zclient->interface_bfd_dest_update = pim_bfd_interface_dest_update; +	zclient->bfd_dest_replay = pim_bfd_nbr_replay;  }  | 
