Beispiel #1
0
static void attributes_show_ipv6(struct nlattr *tb[])
{
	if (tb[RTA_TABLE]) {
		printf("table=%u ", mnl_attr_get_u32(tb[RTA_TABLE]));
	}
	if (tb[RTA_DST]) {
		struct in6_addr *addr = mnl_attr_get_payload(tb[RTA_DST]);
		printf("dst=%s ", inet6_ntoa(*addr));
	}
	if (tb[RTA_SRC]) {
		struct in6_addr *addr = mnl_attr_get_payload(tb[RTA_SRC]);
		printf("src=%s ", inet6_ntoa(*addr));
	}
	if (tb[RTA_OIF]) {
		printf("oif=%u ", mnl_attr_get_u32(tb[RTA_OIF]));
	}
	if (tb[RTA_FLOW]) {
		printf("flow=%u ", mnl_attr_get_u32(tb[RTA_FLOW]));
	}
	if (tb[RTA_PREFSRC]) {
		struct in6_addr *addr = mnl_attr_get_payload(tb[RTA_PREFSRC]);
		printf("prefsrc=%s ", inet6_ntoa(*addr));
	}
	if (tb[RTA_GATEWAY]) {
		struct in6_addr *addr = mnl_attr_get_payload(tb[RTA_GATEWAY]);
		printf("gw=%s ", inet6_ntoa(*addr));
	}
	if (tb[RTA_METRICS]) {
		int i;
		struct nlattr *tbx[RTAX_MAX+1] = {};

		mnl_attr_parse_nested(tb[RTA_METRICS], data_attr_cb2, tbx);

		for (i=0; i<RTAX_MAX; i++) {
			if (tbx[i]) {
				printf("metrics[%d]=%u ",
					i, mnl_attr_get_u32(tbx[i]));
			}
		}
	}
	printf("\n");
}
Beispiel #2
0
void ripng_peer_display(struct vty *vty, struct ripng *ripng)
{
	struct ripng_peer *peer;
	struct listnode *node, *nnode;
#define RIPNG_UPTIME_LEN 25
	char timebuf[RIPNG_UPTIME_LEN];

	for (ALL_LIST_ELEMENTS(ripng->peer_list, node, nnode, peer)) {
		vty_out(vty, "    %s \n%14s %10d %10d %10d      %s\n",
			inet6_ntoa(peer->addr), " ", peer->recv_badpackets,
			peer->recv_badroutes, ZEBRA_RIPNG_DISTANCE_DEFAULT,
			ripng_peer_uptime(peer, timebuf, RIPNG_UPTIME_LEN));
	}
}
int
ripng_interface_address_add (int command, struct zclient *zclient,
			     zebra_size_t length)
{
  struct connected *c;
  struct prefix *p;

  c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, 
                                    zclient->ibuf);

  if (c == NULL)
    return 0;

  p = c->address;

  if (p->family == AF_INET6)
    {
      struct ripng_interface *ri = c->ifp->info;
      
      if (IS_RIPNG_DEBUG_ZEBRA)
	zlog_debug ("RIPng connected address %s/%d add",
		   inet6_ntoa(p->u.prefix6),
		   p->prefixlen);
      
      /* Check is this prefix needs to be redistributed. */
      ripng_apply_address_add(c);

      /* Let's try once again whether the interface could be activated */
      if (!ri->running) {
        /* Check if this interface is RIP enabled or not.*/
        ripng_enable_apply (c->ifp);

        /* Apply distribute list to the interface. */
        ripng_distribute_update_interface (c->ifp);

        /* Check interface routemap. */
        ripng_if_rmap_update_interface (c->ifp);
      }

    }

  return 0;
}
Beispiel #4
0
void tcpserver6(void)
{
	int sockfd, clientfd;
	struct sockaddr_in6 server_addr6, client_addr6;
	int bytes_received;
	char *recv_data;
	UInt32 sin_size;
	rt_bool_t stop = RT_FALSE;

	recv_data = malloc(BUF_SIZE);
	if(recv_data == NULL)
	{
		printf("No memory\n");
		return ;
	}

	if((sockfd = socket(PF_INET6, SOCK_STREAM, 0)) == -1)
	{
		printf("Socket error\n");
		rt_free(recv_data);
		return ;
	}

	server_addr6.sin6_family = AF_INET6;
	memcpy(server_addr6.sin6_addr.s6_addr, IP6_ADDR_ANY, 16);
	server_addr6.sin6_port = htons(SERV_PORT);

	if(bind(sockfd, (struct sockaddr *)&server_addr6, sizeof(struct sockaddr)) == -1)
	{
		printf("Bind error\n");
		rt_free(recv_data);
		return ;
	}
	if(listen(sockfd, BACKLOG) == -1)
	{
		printf("Listen error\n");
		rt_free(recv_data);
		return ;
	}

	rt_sprintf(recv_data, "%4d", SERV_PORT);
	printf("\nTCPServer Waiting for client on port %s...\n", recv_data);

	while(stop != RT_TRUE)
	{
		sin_size = sizeof(struct sockaddr_in6);
		clientfd = accept(sockfd, (struct sockaddr *)&client_addr6, &sin_size);
		printf("I got a connection from (IP:%s, PORT:%d\n)", inet6_ntoa(client_addr6.sin6_addr), ntohs(client_addr6.sin6_port));
		while(1)
		{
			send(clientfd, send_data, strlen(send_data), 0);

			bytes_received = recv(clientfd, recv_data, BUF_SIZE, 0);
			if(bytes_received <= 0)
			{
				closesocket(clientfd);
				break;
			}
			recv_data[bytes_received] = '\0';
			if(strcmp(recv_data, "q") == 0 || strcmp(recv_data, "Q") == 0)
			{
				closesocket(clientfd);
				break;
			}
			else if(strcmp(recv_data, "exit") == 0)
			{
				closesocket(clientfd);
				stop = RT_TRUE;
				break;
			}
			else
			{
				printf("RECEIVED DATA = %s\n", recv_data);
			}
		}
	}

	closesocket(sockfd);
	rt_free(recv_data);

	return ;
}
Beispiel #5
0
int
babel_filter(int output, const unsigned char *prefix, unsigned short plen,
             unsigned int ifindex)
{
    struct interface *ifp = if_lookup_by_index(ifindex);
    babel_interface_nfo *babel_ifp = ifp ? babel_get_if_nfo(ifp) : NULL;
    struct prefix p;
    struct distribute *dist;
    struct access_list *alist;
    struct prefix_list *plist;
    int filter = output ? BABEL_FILTER_OUT : BABEL_FILTER_IN;
    int distribute = output ? DISTRIBUTE_OUT : DISTRIBUTE_IN;

    p.family = v4mapped(prefix) ? AF_INET : AF_INET6;
    p.prefixlen = v4mapped(prefix) ? plen - 96 : plen;
    if (p.family == AF_INET)
        uchar_to_inaddr(&p.u.prefix4, prefix);
#ifdef HAVE_IPV6
    else
        uchar_to_in6addr(&p.u.prefix6, prefix);
#endif
    if (babel_ifp != NULL && babel_ifp->list[filter]) {
        if (access_list_apply (babel_ifp->list[filter], &p)
            == FILTER_DENY) {
            debugf(BABEL_DEBUG_FILTER,
                   "%s/%d filtered by distribute in",
#ifdef HAVE_IPV6
                   p.family == AF_INET ?
                   inet_ntoa(p.u.prefix4) :
                   inet6_ntoa (p.u.prefix6),
#else
		   inet_ntoa(p.u.prefix4),
#endif
                   p.prefixlen);
            return INFINITY;
	}
    }
    if (babel_ifp != NULL && babel_ifp->prefix[filter]) {
        if (prefix_list_apply (babel_ifp->prefix[filter], &p)
            == PREFIX_DENY) {
            debugf(BABEL_DEBUG_FILTER, "%s/%d filtered by distribute in",
#ifdef HAVE_IPV6
                        p.family == AF_INET ?
                        inet_ntoa(p.u.prefix4) :
                        inet6_ntoa (p.u.prefix6),
#else
                        inet_ntoa(p.u.prefix4),
#endif
                        p.prefixlen);
            return INFINITY;
	}
    }

    /* All interface filter check. */
    dist = distribute_lookup (NULL);
    if (dist) {
        if (dist->list[distribute]) {
            alist = access_list_lookup (AFI_IP6, dist->list[distribute]);

            if (alist) {
                if (access_list_apply (alist, &p) == FILTER_DENY) {
                    debugf(BABEL_DEBUG_FILTER, "%s/%d filtered by distribute in",
#ifdef HAVE_IPV6
                                p.family == AF_INET ?
                                inet_ntoa(p.u.prefix4) :
                                inet6_ntoa (p.u.prefix6),
#else
                                inet_ntoa(p.u.prefix4),
#endif
                                p.prefixlen);
                    return INFINITY;
		}
	    }
	}
        if (dist->prefix[distribute]) {
            plist = prefix_list_lookup (AFI_IP6, dist->prefix[distribute]);
            if (plist) {
                if (prefix_list_apply (plist, &p) == PREFIX_DENY) {
                    debugf(BABEL_DEBUG_FILTER, "%s/%d filtered by distribute in",
#ifdef HAVE_IPV6
                                p.family == AF_INET ?
                                inet_ntoa(p.u.prefix4) :
                                inet6_ntoa (p.u.prefix6),
#else
                                inet_ntoa(p.u.prefix4),
#endif
                                p.prefixlen);
                    return INFINITY;
		}
	    }
	}
    }
    return 0;
}
Beispiel #6
0
/* Send ECMP routes to zebra. */
static void
ripng_zebra_ipv6_send (struct route_node *rp, u_char cmd)
{
  static struct in6_addr **nexthops = NULL;
  static unsigned int *ifindexes = NULL;
  static unsigned int nexthops_len = 0;

  struct list *list = (struct list *)rp->info;
  struct zapi_ipv6 api;
  struct listnode *listnode = NULL;
  struct ripng_info *rinfo = NULL;
  int count = 0;

  if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT))
    {
      api.vrf_id = VRF_DEFAULT;
      api.type = ZEBRA_ROUTE_RIPNG;
      api.flags = 0;
      api.message = 0;
      api.safi = SAFI_UNICAST;

      if (nexthops_len < listcount (list))
        {
          nexthops_len = listcount (list);
          nexthops = XREALLOC (MTYPE_TMP, nexthops,
                               nexthops_len * sizeof (struct in6_addr *));
          ifindexes = XREALLOC (MTYPE_TMP, ifindexes,
                                nexthops_len * sizeof (unsigned int));
        }

      SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
      SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
      for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
        {
          nexthops[count] = &rinfo->nexthop;
          ifindexes[count] = rinfo->ifindex;
          count++;
          if (cmd == ZEBRA_IPV6_ROUTE_ADD)
            SET_FLAG (rinfo->flags, RIPNG_RTF_FIB);
          else
            UNSET_FLAG (rinfo->flags, RIPNG_RTF_FIB);
        }

      api.nexthop = nexthops;
      api.nexthop_num = count;
      api.ifindex = ifindexes;
      api.ifindex_num = count;

      rinfo = listgetdata (listhead (list));

      SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
      api.metric = rinfo->metric;

      zapi_ipv6_route (cmd, zclient,
                       (struct prefix_ipv6 *)&rp->p, &api);

      if (IS_RIPNG_DEBUG_ZEBRA)
        {
          if (ripng->ecmp)
            zlog_debug ("%s: %s/%d nexthops %d",
                        (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
                            "Install into zebra" : "Delete from zebra",
                        inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen, count);
          else
            zlog_debug ("%s: %s/%d",
                        (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
                            "Install into zebra" : "Delete from zebra",
                        inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen);
        }
    }