Exemple #1
0
void
router_id_add_address (struct connected *ifc)
{
  struct list *l = NULL;
  struct listnode *node;
  struct prefix before;
  struct prefix after;
  struct zserv *client;

  if (router_id_bad_address (ifc))
    return;

  router_id_get (&before);

  if (!strncmp (ifc->ifp->name, "lo", 2)
      || !strncmp (ifc->ifp->name, "dummy", 5))
    l = &rid_lo_sorted_list;
  else
    l = &rid_all_sorted_list;
  
  if (!router_id_find_node (l, ifc))
    listnode_add_sort (l, ifc);

  router_id_get (&after);

  if (prefix_same (&before, &after))
    return;

  for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client))
    zsend_router_id_update (client, &after);
}
Exemple #2
0
/* Create new interface structure. */
struct interface *
if_create_vrf (const char *name, int namelen, vrf_id_t vrf_id)
{
  struct interface *ifp;
  struct list *intf_list = vrf_iflist_get (vrf_id);

  ifp = XCALLOC (MTYPE_IF, sizeof (struct interface));
  ifp->ifindex = IFINDEX_INTERNAL;
  
  assert (name);
  assert (namelen <= INTERFACE_NAMSIZ);	/* Need space for '\0' at end. */
  strncpy (ifp->name, name, namelen);
  ifp->name[namelen] = '\0';
  ifp->vrf_id = vrf_id;
  if (if_lookup_by_name_vrf (ifp->name, vrf_id) == NULL)
    listnode_add_sort (intf_list, ifp);
  else
    zlog_err("if_create(%s): corruption detected -- interface with this "
             "name exists already in VRF %u!", ifp->name, vrf_id);
  ifp->connected = list_new ();
  ifp->connected->del = (void (*) (void *)) connected_free;

  if (if_master.if_new_hook)
    (*if_master.if_new_hook) (ifp);

  return ifp;
}
Exemple #3
0
/* Create new interface structure. */
struct interface *
if_create (const char *name, int namelen)
{
  struct interface *ifp;

  ifp = if_lookup_by_name(name);
  if (ifp) {
    if (ifp->ifindex != IFINDEX_INTERNAL)
      zlog_err("if_create(%s): corruption detected -- interface with this "
	       "name exists already!", ifp->name);
  } else {
    ifp = XCALLOC (MTYPE_IF, sizeof (struct interface));
    ifp->ifindex = IFINDEX_INTERNAL;
  
    assert (namelen <= INTERFACE_NAMSIZ);	/* Need space for '\0' at end. */
    strncpy (ifp->name, name, namelen);
    ifp->name[namelen] = '\0';

    listnode_add_sort (iflist, ifp);
  }

  ifp->connected = list_new ();
  ifp->connected->del = (void (*) (void *)) connected_free;
  
  if (if_master.if_new_hook)
    (*if_master.if_new_hook) (ifp);

  return ifp;
}
Exemple #4
0
/* create ospf6_neighbor */
struct ospf6_neighbor *
ospf6_neighbor_create (u_int32_t router_id, struct ospf6_interface *oi)
{
  struct ospf6_neighbor *on;
  char buf[16];

  on = (struct ospf6_neighbor *)
    XMALLOC (MTYPE_OSPF6_NEIGHBOR, sizeof (struct ospf6_neighbor));
  if (on == NULL)
    {
      zlog_warn ("neighbor: malloc failed");
      return NULL;
    }

  memset (on, 0, sizeof (struct ospf6_neighbor));
  inet_ntop (AF_INET, &router_id, buf, sizeof (buf));
  snprintf (on->name, sizeof (on->name), "%s%%%s",
            buf, oi->interface->name);
  on->ospf6_if = oi;
  on->state = OSPF6_NEIGHBOR_DOWN;
  gettimeofday (&on->last_changed, (struct timezone *) NULL);
  on->router_id = router_id;

  on->summary_list = ospf6_lsdb_create (on);
  on->request_list = ospf6_lsdb_create (on);
  on->retrans_list = ospf6_lsdb_create (on);

  on->dbdesc_list = ospf6_lsdb_create (on);
  on->lsreq_list = ospf6_lsdb_create (on);
  on->lsupdate_list = ospf6_lsdb_create (on);
  on->lsack_list = ospf6_lsdb_create (on);

  listnode_add_sort (oi->neighbor_list, on);
  return on;
}
Exemple #5
0
/* Get RIPng peer.  At the same time update timeout thread. */
static struct ripng_peer *ripng_peer_get(struct ripng *ripng,
					 struct in6_addr *addr)
{
	struct ripng_peer *peer;

	peer = ripng_peer_lookup(ripng, addr);

	if (peer) {
		if (peer->t_timeout)
			thread_cancel(peer->t_timeout);
	} else {
		peer = ripng_peer_new();
		peer->ripng = ripng;
		peer->addr = *addr;
		listnode_add_sort(ripng->peer_list, peer);
	}

	/* Update timeout thread. */
	peer->t_timeout = NULL;
	thread_add_timer(master, ripng_peer_timeout, peer,
			 RIPNG_PEER_TIMER_DEFAULT, &peer->t_timeout);

	/* Last update time set. */
	time(&peer->uptime);

	return peer;
}
Exemple #6
0
extern void deleteText(struct list *_this,s32 delete_p,s32 length)
{
    RwRecord * dec = OWJsRewriterRecord(delete_p,NULL,length,0);
    if( !_this->cmp || !_this->tail || !_this->tail->data || _this->cmp(dec,_this->tail->data) > 0 )
        listnode_add(_this,dec);
    else
        listnode_add_sort(_this,(void*)dec);
    DEBUG("%d,%d",delete_p,length);
}
Exemple #7
0
/* 11.2.A1: create a new peer and transition state to listen or connecting */
static enum pim_msdp_err pim_msdp_peer_new(struct pim_instance *pim,
					   struct in_addr peer_addr,
					   struct in_addr local_addr,
					   const char *mesh_group_name,
					   struct pim_msdp_peer **mp_p)
{
	struct pim_msdp_peer *mp;

	pim_msdp_enable(pim);

	mp = XCALLOC(MTYPE_PIM_MSDP_PEER, sizeof(*mp));

	mp->pim = pim;
	mp->peer = peer_addr;
	pim_inet4_dump("<peer?>", mp->peer, mp->key_str, sizeof(mp->key_str));
	pim_msdp_addr2su(&mp->su_peer, mp->peer);
	mp->local = local_addr;
	/* XXX: originator_id setting needs to move to the mesh group */
	pim->msdp.originator_id = local_addr;
	pim_msdp_addr2su(&mp->su_local, mp->local);
	mp->mesh_group_name = XSTRDUP(MTYPE_PIM_MSDP_MG_NAME, mesh_group_name);
	mp->state = PIM_MSDP_INACTIVE;
	mp->fd = -1;
	strlcpy(mp->last_reset, "-", sizeof(mp->last_reset));
	/* higher IP address is listener */
	if (ntohl(mp->local.s_addr) > ntohl(mp->peer.s_addr)) {
		mp->flags |= PIM_MSDP_PEERF_LISTENER;
	}

	/* setup packet buffers */
	mp->ibuf = stream_new(PIM_MSDP_MAX_PACKET_SIZE);
	mp->obuf = stream_fifo_new();

	/* insert into misc tables for easy access */
	mp = hash_get(pim->msdp.peer_hash, mp, hash_alloc_intern);
	listnode_add_sort(pim->msdp.peer_list, mp);

	if (PIM_DEBUG_MSDP_EVENTS) {
		zlog_debug("MSDP peer %s created", mp->key_str);

		pim_msdp_peer_state_chg_log(mp);
	}

	/* fireup the connect state machine */
	if (PIM_MSDP_PEER_IS_LISTENER(mp)) {
		pim_msdp_peer_listen(mp);
	} else {
		pim_msdp_peer_connect(mp);
	}
	if (mp_p) {
		*mp_p = mp;
	}
	return PIM_MSDP_ERR_NONE;
}
Exemple #8
0
extern void insertText(struct list *_this,
                       s32 insert_p,s32 pre_item,u8* str)
{
    RwRecord * inc = OWJsRewriterRecord(insert_p,str,strlen((const char*)str),pre_item);
    inc->insert = (u8*)calloc(1,inc->length+1);
    memcpy(inc->insert,str,inc->length);
    if( !_this->cmp || !_this->tail || !_this->tail->data || _this->cmp(inc,_this->tail->data) > 0 )
        listnode_add(_this,inc);
    else
        listnode_add_sort(_this,(void*)inc);
    DEBUG("%d,%d,%s",insert_p,pre_item,str);
}
Exemple #9
0
static void
config_add_line_uniq (struct list *config, const char *line)
{
  struct listnode *node, *nnode;
  char *pnt;

  for (ALL_LIST_ELEMENTS (config, node, nnode, pnt))
    {
      if (strcmp (pnt, line) == 0)
	return;
    }
  listnode_add_sort (config, XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line));
}
Exemple #10
0
void
config_add_line_uniq (struct list *config, char *line)
{
  struct listnode *nn;
  char *pnt;

  LIST_LOOP (config, pnt, nn)
    {
      if (strcmp (pnt, line) == 0)
	return;
    }
  listnode_add_sort (config, XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line));
}
Exemple #11
0
static struct key *key_get(const struct keychain *keychain, uint32_t index)
{
	struct key *key;

	key = key_lookup(keychain, index);

	if (key)
		return key;

	key = key_new();
	key->index = index;
	listnode_add_sort(keychain->key, key);

	return key;
}
Exemple #12
0
/* Make new area structure */
struct ospf6_area *
ospf6_area_create (u_int32_t area_id, struct ospf6 *o)
{
  struct ospf6_area *oa;
  struct ospf6_route *route;

  oa = XCALLOC (MTYPE_OSPF6_AREA, sizeof (struct ospf6_area));

  inet_ntop (AF_INET, &area_id, oa->name, sizeof (oa->name));
  oa->area_id = area_id;
  oa->if_list = list_new ();

  oa->lsdb = ospf6_lsdb_create (oa);
  oa->lsdb->hook_add = ospf6_area_lsdb_hook_add;
  oa->lsdb->hook_remove = ospf6_area_lsdb_hook_remove;
  oa->lsdb_self = ospf6_lsdb_create (oa);

  oa->spf_table = OSPF6_ROUTE_TABLE_CREATE (AREA, SPF_RESULTS);
  oa->spf_table->scope = oa;
  oa->route_table = OSPF6_ROUTE_TABLE_CREATE (AREA, ROUTES);
  oa->route_table->scope = oa;
  oa->route_table->hook_add = ospf6_area_route_hook_add;
  oa->route_table->hook_remove = ospf6_area_route_hook_remove;

  oa->range_table = OSPF6_ROUTE_TABLE_CREATE (AREA, PREFIX_RANGES);
  oa->range_table->scope = oa;
  oa->summary_prefix = OSPF6_ROUTE_TABLE_CREATE (AREA, SUMMARY_PREFIXES);
  oa->summary_prefix->scope = oa;
  oa->summary_router = OSPF6_ROUTE_TABLE_CREATE (AREA, SUMMARY_ROUTERS);
  oa->summary_router->scope = oa;

  /* set default options */
  OSPF6_OPT_SET (oa->options, OSPF6_OPT_V6);
  OSPF6_OPT_SET (oa->options, OSPF6_OPT_E);
  OSPF6_OPT_SET (oa->options, OSPF6_OPT_R);

  oa->ospf6 = o;
  listnode_add_sort (o->area_list, oa);

  /* import athoer area's routes as inter-area routes */
  for (route = ospf6_route_head (o->route_table); route;
       route = ospf6_route_next (route))
    ospf6_abr_originate_summary_to_area (route, oa);

  return oa;
}
Exemple #13
0
enum pim_msdp_err pim_msdp_mg_mbr_add(struct pim_instance *pim,
				      const char *mesh_group_name,
				      struct in_addr mbr_ip)
{
	int rc;
	struct pim_msdp_mg_mbr *mbr;
	struct pim_msdp_mg *mg;

	rc = pim_msdp_mg_add(pim, mesh_group_name);
	if (rc != PIM_MSDP_ERR_NONE) {
		return rc;
	}

	mg = pim->msdp.mg;
	mbr = pim_msdp_mg_mbr_find(pim, mbr_ip);
	if (mbr) {
		return PIM_MSDP_ERR_MG_MBR_EXISTS;
	}

	mbr = XCALLOC(MTYPE_PIM_MSDP_MG_MBR, sizeof(*mbr));
	mbr->mbr_ip = mbr_ip;
	listnode_add_sort(mg->mbr_list, mbr);

	/* if valid SIP has been configured add peer session */
	if (mg->src_ip.s_addr != INADDR_ANY) {
		pim_msdp_peer_add(pim, mbr_ip, mg->src_ip, mesh_group_name,
				  &mbr->mp);
	}

	if (PIM_DEBUG_MSDP_EVENTS) {
		char ip_str[INET_ADDRSTRLEN];
		pim_inet4_dump("<mbr?>", mbr->mbr_ip, ip_str, sizeof(ip_str));
		zlog_debug("MSDP mesh-group %s mbr %s created",
			   mg->mesh_group_name, ip_str);
	}
	++mg->mbr_cnt;
	return PIM_MSDP_ERR_NONE;
}
Exemple #14
0
static struct pim_msdp_sa *pim_msdp_sa_new(struct pim_instance *pim,
					   struct prefix_sg *sg,
					   struct in_addr rp)
{
	struct pim_msdp_sa *sa;

	sa = XCALLOC(MTYPE_PIM_MSDP_SA, sizeof(*sa));

	sa->pim = pim;
	sa->sg = *sg;
	pim_str_sg_set(sg, sa->sg_str);
	sa->rp = rp;
	sa->uptime = pim_time_monotonic_sec();

	/* insert into misc tables for easy access */
	sa = hash_get(pim->msdp.sa_hash, sa, hash_alloc_intern);
	listnode_add_sort(pim->msdp.sa_list, sa);

	if (PIM_DEBUG_MSDP_EVENTS) {
		zlog_debug("MSDP SA %s created", sa->sg_str);
	}

	return sa;
}
Exemple #15
0
/*******************************************************************************
 函数名称  : bgp_mp_list_add
 功能描述  : mpath 链表添加
 输入参数  : 
 输出参数  : 
 返 回 值  : 无
--------------------------------------------------------------------------------
 最近一次修改记录 :
 修改作者   :      
 修改目的   :      新添加函数
 修改日期   :       2012-8-15
*******************************************************************************/
void bgp_mp_list_add (struct list *mp_list, struct bgp_info *mpinfo)
{
	listnode_add_sort (mp_list, mpinfo);
}
Exemple #16
0
static int
ospf6_spf_install (struct ospf6_vertex *v,
                   struct ospf6_route_table *result_table)
{
  struct ospf6_route *route;
  int i, j;
  struct ospf6_vertex *prev;

  if (IS_OSPF6_DEBUG_SPF (PROCESS))
    zlog_debug ("SPF install %s hops %d cost %d",
		v->name, v->hops, v->cost);

  route = ospf6_route_lookup (&v->vertex_id, result_table);
  if (route && route->path.cost < v->cost)
    {
      if (IS_OSPF6_DEBUG_SPF (PROCESS))
        zlog_debug ("  already installed with lower cost (%d), ignore",
		    route->path.cost);
      ospf6_vertex_delete (v);
      return -1;
    }
  else if (route && route->path.cost == v->cost)
    {
      if (IS_OSPF6_DEBUG_SPF (PROCESS))
        zlog_debug ("  another path found, merge");

      for (i = 0; ospf6_nexthop_is_set (&v->nexthop[i]) &&
           i < OSPF6_MULTI_PATH_LIMIT; i++)
        {
          for (j = 0; j < OSPF6_MULTI_PATH_LIMIT; j++)
            {
              if (ospf6_nexthop_is_set (&route->nexthop[j]))
                {
                  if (ospf6_nexthop_is_same (&route->nexthop[j],
                                             &v->nexthop[i]))
                    break;
                  else
                    continue;
                }
              ospf6_nexthop_copy (&route->nexthop[j], &v->nexthop[i]);
              break;
            }
        }

      prev = (struct ospf6_vertex *) route->route_option;
      assert (prev->hops <= v->hops);
      ospf6_vertex_delete (v);

      return -1;
    }

  /* There should be no case where candidate being installed (variable
     "v") is closer than the one in the SPF tree (variable "route").
     In the case something has gone wrong with the behavior of
     Priority-Queue. */

  /* the case where the route exists already is handled and returned
     up to here. */
  assert (route == NULL);

  route = ospf6_route_create ();
  memcpy (&route->prefix, &v->vertex_id, sizeof (struct prefix));
  route->type = OSPF6_DEST_TYPE_LINKSTATE;
  route->path.type = OSPF6_PATH_TYPE_INTRA;
  route->path.origin.type = v->lsa->header->type;
  route->path.origin.id = v->lsa->header->id;
  route->path.origin.adv_router = v->lsa->header->adv_router;
  route->path.metric_type = 1;
  route->path.cost = v->cost;
  route->path.cost_e2 = v->hops;
  route->path.router_bits = v->capability;
  route->path.options[0] = v->options[0];
  route->path.options[1] = v->options[1];
  route->path.options[2] = v->options[2];

  for (i = 0; ospf6_nexthop_is_set (&v->nexthop[i]) &&
       i < OSPF6_MULTI_PATH_LIMIT; i++)
    ospf6_nexthop_copy (&route->nexthop[i], &v->nexthop[i]);

  if (v->parent)
    listnode_add_sort (v->parent->child_list, v);
  route->route_option = v;

  ospf6_route_add (route, result_table);
  return 0;
}
Exemple #17
0
static u_char *
ospfv3WwLsdbEntry (struct variable *v, oid *name, size_t *length,
                     int exact, size_t *var_len, WriteMethod **write_method)
{
  struct ospf6_lsa *lsa = NULL;
  u_int32_t ifindex, area_id, id, instid, adv_router;
  u_int16_t type;
  int len;
  oid *offset;
  int offsetlen;
  char a[16], b[16], c[16];
  struct ospf6_area *oa;
  struct listnode *node;
  struct interface *iif;
  struct ospf6_interface *oi = NULL;
  struct list *ifslist;

  if (smux_header_table(v, name, length, exact, var_len, write_method)
      == MATCH_FAILED)
    return NULL;

  instid = ifindex = area_id = type = id = adv_router = 0;

  /* Check OSPFv3 instance. */
  if (ospf6 == NULL)
    return NULL;

  /* Get variable length. */
  offset = name + v->namelen;
  offsetlen = *length - v->namelen;

  if (exact && (v->magic & OSPFv3WWASTABLE) && offsetlen != 3)
    return NULL;
  if (exact && (v->magic & OSPFv3WWAREATABLE) && offsetlen != 4)
    return NULL;
  if (exact && (v->magic & OSPFv3WWLINKTABLE) && offsetlen != 5)
    return NULL;

  if (v->magic & OSPFv3WWLINKTABLE)
    {
      /* Parse ifindex */
      len = (offsetlen < 1 ? 0 : 1);
      if (len)
        ifindex = *offset;
      offset += len;
      offsetlen -= len;

      /* Parse instance ID */
      len = (offsetlen < 1 ? 0 : 1);
      if (len)
        instid = *offset;
      offset += len;
      offsetlen -= len;
    }
  else if (v->magic & OSPFv3WWAREATABLE)
    {
      /* Parse area-id */
      len = (offsetlen < 1 ? 0 : 1);
      if (len)
        area_id = htonl (*offset);
      offset += len;
      offsetlen -= len;
    }

  /* Parse type */
  len = (offsetlen < 1 ? 0 : 1);
  if (len)
    type = htons (*offset);
  offset += len;
  offsetlen -= len;

  /* Parse Router-ID */
  len = (offsetlen < 1 ? 0 : 1);
  if (len)
    adv_router = htonl (*offset);
  offset += len;
  offsetlen -= len;

  /* Parse LS-ID */
  len = (offsetlen < 1 ? 0 : 1);
  if (len)
    id = htonl (*offset);
  offset += len;
  offsetlen -= len;

  if (exact)
    {
      if (v->magic & OSPFv3WWASTABLE)
        {
          lsa = ospf6_lsdb_lookup (type, id, adv_router, ospf6->lsdb);
        }
      else if (v->magic & OSPFv3WWAREATABLE)
        {
          oa = ospf6_area_lookup (area_id, ospf6);
          if (!oa) return NULL;
          lsa = ospf6_lsdb_lookup (type, id, adv_router, oa->lsdb);
        }
      else if (v->magic & OSPFv3WWLINKTABLE)
        {
          oi = ospf6_interface_lookup_by_ifindex (ifindex);
          if (!oi || oi->instance_id != instid) return NULL;
          lsa = ospf6_lsdb_lookup (type, id, adv_router, oi->lsdb);
        }
    }
  else
    {
      if (v->magic & OSPFv3WWASTABLE)
	{
	  if (ospf6->lsdb->count)
	    lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
					  ospf6->lsdb);
	}
      else if (v->magic & OSPFv3WWAREATABLE)
	for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
          {
            if (oa->area_id < area_id)
              continue;

            if (oa->lsdb->count)
              lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
                                            oa->lsdb);
            if (lsa) break;
            type = 0;
            id = 0;
            adv_router = 0;
          }
      else if (v->magic & OSPFv3WWLINKTABLE)
        {
          /* We build a sorted list of interfaces */
          ifslist = list_new ();
          if (!ifslist) return NULL;
          ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
          for (ALL_LIST_ELEMENTS_RO (iflist, node, iif))
            listnode_add_sort (ifslist, iif);
          
          for (ALL_LIST_ELEMENTS_RO (ifslist, node, iif))
            {
              if (!iif->ifindex) continue;
              oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
              if (!oi) continue;
              if (iif->ifindex < ifindex) continue;
              if (oi->instance_id < instid) continue;
              
              if (oi->lsdb->count)
                lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
                                            oi->lsdb);
              if (lsa) break;
              type = 0;
              id = 0;
              adv_router = 0;
              oi = NULL;
            }

          list_delete_all_node (ifslist);
        }