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 /lib/nexthop.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 'lib/nexthop.c')
| -rw-r--r-- | lib/nexthop.c | 337 | 
1 files changed, 160 insertions, 177 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c index e9ffea0a0e..9b0c2d73f4 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -32,216 +32,201 @@  #include "nexthop.h"  #include "mpls.h" -DEFINE_MTYPE_STATIC(LIB, NEXTHOP,	"Nexthop") -DEFINE_MTYPE_STATIC(LIB, NH_LABEL,	"Nexthop label") +DEFINE_MTYPE_STATIC(LIB, NEXTHOP, "Nexthop") +DEFINE_MTYPE_STATIC(LIB, NH_LABEL, "Nexthop label")  /* check if nexthops are same, non-recursive */ -int -nexthop_same_no_recurse (struct nexthop *next1, struct nexthop *next2) +int nexthop_same_no_recurse(struct nexthop *next1, struct nexthop *next2)  { -  if (next1->type != next2->type) -    return 0; - -  switch (next1->type) -    { -    case NEXTHOP_TYPE_IPV4: -    case NEXTHOP_TYPE_IPV4_IFINDEX: -      if (! IPV4_ADDR_SAME (&next1->gate.ipv4, &next2->gate.ipv4)) -	return 0; -      if (next1->ifindex && (next1->ifindex != next2->ifindex)) -	return 0; -      break; -    case NEXTHOP_TYPE_IFINDEX: -      if (next1->ifindex != next2->ifindex) -	return 0; -      break; -    case NEXTHOP_TYPE_IPV6: -      if (! IPV6_ADDR_SAME (&next1->gate.ipv6, &next2->gate.ipv6)) -	return 0; -      break; -    case NEXTHOP_TYPE_IPV6_IFINDEX: -      if (! IPV6_ADDR_SAME (&next1->gate.ipv6, &next2->gate.ipv6)) -	return 0; -      if (next1->ifindex != next2->ifindex) -	return 0; -      break; -    default: -      /* do nothing */ -      break; -    } -  return 1; +	if (next1->type != next2->type) +		return 0; + +	switch (next1->type) { +	case NEXTHOP_TYPE_IPV4: +	case NEXTHOP_TYPE_IPV4_IFINDEX: +		if (!IPV4_ADDR_SAME(&next1->gate.ipv4, &next2->gate.ipv4)) +			return 0; +		if (next1->ifindex && (next1->ifindex != next2->ifindex)) +			return 0; +		break; +	case NEXTHOP_TYPE_IFINDEX: +		if (next1->ifindex != next2->ifindex) +			return 0; +		break; +	case NEXTHOP_TYPE_IPV6: +		if (!IPV6_ADDR_SAME(&next1->gate.ipv6, &next2->gate.ipv6)) +			return 0; +		break; +	case NEXTHOP_TYPE_IPV6_IFINDEX: +		if (!IPV6_ADDR_SAME(&next1->gate.ipv6, &next2->gate.ipv6)) +			return 0; +		if (next1->ifindex != next2->ifindex) +			return 0; +		break; +	default: +		/* do nothing */ +		break; +	} +	return 1;  }  /*   * nexthop_type_to_str   */ -const char * -nexthop_type_to_str (enum nexthop_types_t nh_type) +const char *nexthop_type_to_str(enum nexthop_types_t nh_type)  { -  static const char *desc[] = { -    "none", -    "Directly connected", -    "IPv4 nexthop", -    "IPv4 nexthop with ifindex", -    "IPv6 nexthop", -    "IPv6 nexthop with ifindex", -    "Null0 nexthop", -  }; - -  return desc[nh_type]; +	static const char *desc[] = { +		"none",		 "Directly connected", +		"IPv4 nexthop",  "IPv4 nexthop with ifindex", +		"IPv6 nexthop",  "IPv6 nexthop with ifindex", +		"Null0 nexthop", +	}; + +	return desc[nh_type];  }  /*   * Check if the labels match for the 2 nexthops specified.   */ -int -nexthop_labels_match (struct nexthop *nh1, struct nexthop *nh2) +int nexthop_labels_match(struct nexthop *nh1, struct nexthop *nh2)  { -  struct nexthop_label *nhl1, *nhl2; +	struct nexthop_label *nhl1, *nhl2; -  nhl1 = nh1->nh_label; -  nhl2 = nh2->nh_label; -  if ((nhl1 && !nhl2) || (!nhl1 && nhl2)) -    return 0; +	nhl1 = nh1->nh_label; +	nhl2 = nh2->nh_label; +	if ((nhl1 && !nhl2) || (!nhl1 && nhl2)) +		return 0; -  if (nhl1->num_labels != nhl2->num_labels) -    return 0; +	if (nhl1->num_labels != nhl2->num_labels) +		return 0; -  if (memcmp (nhl1->label, nhl2->label, nhl1->num_labels)) -    return 0; +	if (memcmp(nhl1->label, nhl2->label, nhl1->num_labels)) +		return 0; -  return 1; +	return 1;  } -struct nexthop * -nexthop_new (void) +struct nexthop *nexthop_new(void)  { -  return XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); +	return XCALLOC(MTYPE_NEXTHOP, sizeof(struct nexthop));  }  /* Add nexthop to the end of a nexthop list.  */ -void -nexthop_add (struct nexthop **target, struct nexthop *nexthop) +void nexthop_add(struct nexthop **target, struct nexthop *nexthop)  { -  struct nexthop *last; - -  for (last = *target; last && last->next; last = last->next) -    ; -  if (last) -    last->next = nexthop; -  else -    *target = nexthop; -  nexthop->prev = last; +	struct nexthop *last; + +	for (last = *target; last && last->next; last = last->next) +		; +	if (last) +		last->next = nexthop; +	else +		*target = nexthop; +	nexthop->prev = last;  } -void -copy_nexthops (struct nexthop **tnh, struct nexthop *nh, struct nexthop *rparent) +void copy_nexthops(struct nexthop **tnh, struct nexthop *nh, +		   struct nexthop *rparent)  { -  struct nexthop *nexthop; -  struct nexthop *nh1; - -  for (nh1 = nh; nh1; nh1 = nh1->next) -    { -      nexthop = nexthop_new(); -      nexthop->ifindex = nh->ifindex; -      nexthop->type = nh->type; -      nexthop->flags = nh->flags; -      memcpy(&nexthop->gate, &nh->gate, sizeof(nh->gate)); -      memcpy(&nexthop->src, &nh->src, sizeof(nh->src)); -      memcpy(&nexthop->rmap_src, &nh->rmap_src, sizeof(nh->rmap_src)); -      nexthop->rparent = rparent; -      if (nh->nh_label) -        nexthop_add_labels (nexthop, nh->nh_label_type, -                nh->nh_label->num_labels, &nh->nh_label->label[0]); -      nexthop_add(tnh, nexthop); - -      if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE)) -        copy_nexthops(&nexthop->resolved, nh1->resolved, nexthop); -    } +	struct nexthop *nexthop; +	struct nexthop *nh1; + +	for (nh1 = nh; nh1; nh1 = nh1->next) { +		nexthop = nexthop_new(); +		nexthop->ifindex = nh->ifindex; +		nexthop->type = nh->type; +		nexthop->flags = nh->flags; +		memcpy(&nexthop->gate, &nh->gate, sizeof(nh->gate)); +		memcpy(&nexthop->src, &nh->src, sizeof(nh->src)); +		memcpy(&nexthop->rmap_src, &nh->rmap_src, sizeof(nh->rmap_src)); +		nexthop->rparent = rparent; +		if (nh->nh_label) +			nexthop_add_labels(nexthop, nh->nh_label_type, +					   nh->nh_label->num_labels, +					   &nh->nh_label->label[0]); +		nexthop_add(tnh, nexthop); + +		if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE)) +			copy_nexthops(&nexthop->resolved, nh1->resolved, +				      nexthop); +	}  }  /* Free nexthop. */ -void -nexthop_free (struct nexthop *nexthop) +void nexthop_free(struct nexthop *nexthop)  { -  nexthop_del_labels (nexthop); -  if (nexthop->resolved) -    nexthops_free(nexthop->resolved); -  XFREE (MTYPE_NEXTHOP, nexthop); +	nexthop_del_labels(nexthop); +	if (nexthop->resolved) +		nexthops_free(nexthop->resolved); +	XFREE(MTYPE_NEXTHOP, nexthop);  }  /* Frees a list of nexthops */ -void -nexthops_free (struct nexthop *nexthop) +void nexthops_free(struct nexthop *nexthop)  { -  struct nexthop *nh, *next; +	struct nexthop *nh, *next; -  for (nh = nexthop; nh; nh = next) -    { -      next = nh->next; -      nexthop_free (nh); -    } +	for (nh = nexthop; nh; nh = next) { +		next = nh->next; +		nexthop_free(nh); +	}  }  /* Update nexthop with label information. */ -void -nexthop_add_labels (struct nexthop *nexthop, enum lsp_types_t type, -		    u_int8_t num_labels, mpls_label_t *label) +void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t type, +			u_int8_t num_labels, mpls_label_t *label)  { -  struct nexthop_label *nh_label; -  int i; - -  nexthop->nh_label_type = type; -  nh_label = XCALLOC (MTYPE_NH_LABEL, sizeof (struct nexthop_label) + -		      num_labels * sizeof (mpls_label_t)); -  nh_label->num_labels = num_labels; -  for (i = 0; i < num_labels; i++) -    nh_label->label[i] = *(label + i); -  nexthop->nh_label = nh_label; +	struct nexthop_label *nh_label; +	int i; + +	nexthop->nh_label_type = type; +	nh_label = XCALLOC(MTYPE_NH_LABEL, +			   sizeof(struct nexthop_label) +				   + num_labels * sizeof(mpls_label_t)); +	nh_label->num_labels = num_labels; +	for (i = 0; i < num_labels; i++) +		nh_label->label[i] = *(label + i); +	nexthop->nh_label = nh_label;  }  /* Free label information of nexthop, if present. */ -void -nexthop_del_labels (struct nexthop *nexthop) +void nexthop_del_labels(struct nexthop *nexthop)  { -  if (nexthop->nh_label) -    { -      XFREE (MTYPE_NH_LABEL, nexthop->nh_label); -      nexthop->nh_label_type = ZEBRA_LSP_NONE; -    } +	if (nexthop->nh_label) { +		XFREE(MTYPE_NH_LABEL, nexthop->nh_label); +		nexthop->nh_label_type = ZEBRA_LSP_NONE; +	}  } -const char * -nexthop2str (struct nexthop *nexthop, char *str, int size) +const char *nexthop2str(struct nexthop *nexthop, char *str, int size)  { -  switch (nexthop->type) -    { -      case NEXTHOP_TYPE_IFINDEX: -        snprintf (str, size, "if %u", nexthop->ifindex); -        break; -      case NEXTHOP_TYPE_IPV4: -        snprintf (str, size, "%s", inet_ntoa (nexthop->gate.ipv4)); -        break; -      case NEXTHOP_TYPE_IPV4_IFINDEX: -        snprintf (str, size, "%s if %u", -                  inet_ntoa (nexthop->gate.ipv4), nexthop->ifindex); -        break; -      case NEXTHOP_TYPE_IPV6: -        snprintf (str, size, "%s", inet6_ntoa (nexthop->gate.ipv6)); -        break; -      case NEXTHOP_TYPE_IPV6_IFINDEX: -        snprintf (str, size, "%s if %u", -                  inet6_ntoa (nexthop->gate.ipv6), nexthop->ifindex); -        break; -      case NEXTHOP_TYPE_BLACKHOLE: -        snprintf (str, size, "blackhole"); -        break; -      default: -        snprintf (str, size, "unknown"); -        break; -    } - -  return str; +	switch (nexthop->type) { +	case NEXTHOP_TYPE_IFINDEX: +		snprintf(str, size, "if %u", nexthop->ifindex); +		break; +	case NEXTHOP_TYPE_IPV4: +		snprintf(str, size, "%s", inet_ntoa(nexthop->gate.ipv4)); +		break; +	case NEXTHOP_TYPE_IPV4_IFINDEX: +		snprintf(str, size, "%s if %u", inet_ntoa(nexthop->gate.ipv4), +			 nexthop->ifindex); +		break; +	case NEXTHOP_TYPE_IPV6: +		snprintf(str, size, "%s", inet6_ntoa(nexthop->gate.ipv6)); +		break; +	case NEXTHOP_TYPE_IPV6_IFINDEX: +		snprintf(str, size, "%s if %u", inet6_ntoa(nexthop->gate.ipv6), +			 nexthop->ifindex); +		break; +	case NEXTHOP_TYPE_BLACKHOLE: +		snprintf(str, size, "blackhole"); +		break; +	default: +		snprintf(str, size, "unknown"); +		break; +	} + +	return str;  }  /* @@ -259,29 +244,27 @@ nexthop2str (struct nexthop *nexthop, char *str, int size)   * left branch is 'resolved' and right branch is 'next':   * https://en.wikipedia.org/wiki/Tree_traversal#/media/File:Sorted_binary_tree_preorder.svg   */ -struct nexthop * -nexthop_next(struct nexthop *nexthop) +struct nexthop *nexthop_next(struct nexthop *nexthop)  { -  if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) -    return nexthop->resolved; +	if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) +		return nexthop->resolved; -  if (nexthop->next) -    return nexthop->next; +	if (nexthop->next) +		return nexthop->next; -  for (struct nexthop *par = nexthop->rparent; par; par = par->rparent) -    if (par->next) -      return par->next; +	for (struct nexthop *par = nexthop->rparent; par; par = par->rparent) +		if (par->next) +			return par->next; -  return NULL; +	return NULL;  } -unsigned int -nexthop_level(struct nexthop *nexthop) +unsigned int nexthop_level(struct nexthop *nexthop)  { -  unsigned int rv = 0; +	unsigned int rv = 0; -  for (struct nexthop *par = nexthop->rparent; par; par = par->rparent) -    rv++; +	for (struct nexthop *par = nexthop->rparent; par; par = par->rparent) +		rv++; -  return rv; +	return rv;  }  | 
