コード例 #1
0
/* Unset distribute-list.  If matched distribute-list exist then
   return 1. */
static int
distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
			      const char *plist_name)
{
  struct distribute *dist;

  dist = distribute_lookup (ifname);
  if (!dist)
    return 0;

  if (!dist->prefix[type])
    return 0;
  if (strcmp (dist->prefix[type], plist_name) != 0)
    return 0;

  free (dist->prefix[type]);
  dist->prefix[type] = NULL;

  /* Apply this distribute-list to the interface. */
  (*distribute_delete_hook) (dist);

  /* If all dist are NULL, then free distribute list. */
  distribute_free_if_empty(dist);
  return 1;
}
コード例 #2
0
ファイル: distribute.c プロジェクト: Emat12/OSPFN2.0
/* Unset distribute-list.  If matched distribute-list exist then
   return 1. */
static int
distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
			      const char *plist_name)
{
  struct distribute *dist;

  dist = distribute_lookup (ifname);
  if (!dist)
    return 0;

  if (type == DISTRIBUTE_IN)
    {
      if (!dist->prefix[DISTRIBUTE_IN])
	return 0;
      if (strcmp (dist->prefix[DISTRIBUTE_IN], plist_name) != 0)
	return 0;

      free (dist->prefix[DISTRIBUTE_IN]);
      dist->prefix[DISTRIBUTE_IN] = NULL;      
    }

  if (type == DISTRIBUTE_OUT)
    {
      if (!dist->prefix[DISTRIBUTE_OUT])
	return 0;
      if (strcmp (dist->prefix[DISTRIBUTE_OUT], plist_name) != 0)
	return 0;

      free (dist->prefix[DISTRIBUTE_OUT]);
      dist->prefix[DISTRIBUTE_OUT] = NULL;      
    }

  /* Apply this distribute-list to the interface. */
  (*distribute_delete_hook) (dist);

  /* If both out and in is NULL then free distribute list. */
  if (dist->list[DISTRIBUTE_IN] == NULL &&
      dist->list[DISTRIBUTE_OUT] == NULL &&
      dist->prefix[DISTRIBUTE_IN] == NULL &&
      dist->prefix[DISTRIBUTE_OUT] == NULL)
    {
      hash_release (disthash, dist);
      distribute_free (dist);
    }

  return 1;
}
コード例 #3
0
ファイル: babel_filter.c プロジェクト: MichaelQQ/Quagga-PE
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;
}