static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *);
static __inline int l2vpn_compare(struct l2vpn *, struct l2vpn *);
static __inline int l2vpn_if_compare(struct l2vpn_if *, struct l2vpn_if *);
+static __inline int l2vpn_pw_compare(struct l2vpn_pw *, struct l2vpn_pw *);
RB_GENERATE(l2vpn_head, l2vpn, entry, l2vpn_compare)
RB_GENERATE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare)
+RB_GENERATE(l2vpn_pw_head, l2vpn_pw, entry, l2vpn_pw_compare)
static __inline int
l2vpn_compare(struct l2vpn *a, struct l2vpn *b)
l2vpn->pw_type = DEFAULT_PW_TYPE;
RB_INIT(&l2vpn->if_tree);
- LIST_INIT(&l2vpn->pw_list);
- LIST_INIT(&l2vpn->pw_inactive_list);
+ RB_INIT(&l2vpn->pw_tree);
+ RB_INIT(&l2vpn->pw_inactive_tree);
return (l2vpn);
}
RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif);
free(lif);
}
- while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) {
- LIST_REMOVE(pw, entry);
+ while ((pw = RB_ROOT(&l2vpn->pw_tree)) != NULL) {
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
free(pw);
}
- while ((pw = LIST_FIRST(&l2vpn->pw_inactive_list)) != NULL) {
- LIST_REMOVE(pw, entry);
+ while ((pw = RB_ROOT(&l2vpn->pw_inactive_tree)) != NULL) {
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
free(pw);
}
{
struct l2vpn_pw *pw;
- LIST_FOREACH(pw, &l2vpn->pw_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree)
l2vpn_pw_init(pw);
}
{
struct l2vpn_pw *pw;
- LIST_FOREACH(pw, &l2vpn->pw_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree)
l2vpn_pw_exit(pw);
}
return (RB_FIND(l2vpn_if_head, &l2vpn->if_tree, &lif));
}
+static __inline int
+l2vpn_pw_compare(struct l2vpn_pw *a, struct l2vpn_pw *b)
+{
+ return (strcmp(a->ifname, b->ifname));
+}
struct l2vpn_pw *
l2vpn_pw_new(struct l2vpn *l2vpn, struct kif *kif)
{
struct l2vpn_pw *pw;
- LIST_FOREACH(pw, &l2vpn->pw_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree)
if (pw->ifindex == ifindex)
return (pw);
- LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree)
if (pw->ifindex == ifindex)
return (pw);
l2vpn_pw_find_name(struct l2vpn *l2vpn, const char *ifname)
{
struct l2vpn_pw *pw;
+ struct l2vpn_pw s;
- LIST_FOREACH(pw, &l2vpn->pw_list, entry)
- if (strcmp(pw->ifname, ifname) == 0)
- return (pw);
- LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry)
- if (strcmp(pw->ifname, ifname) == 0)
- return (pw);
-
- return (NULL);
+ strlcpy(s.ifname, ifname, sizeof(s.ifname));
+ pw = RB_FIND(l2vpn_pw_head, &l2vpn->pw_tree, &s);
+ if (pw)
+ return (pw);
+ return (RB_FIND(l2vpn_pw_head, &l2vpn->pw_inactive_tree, &s));
}
void
struct fec_nh *fnh;
RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) {
- LIST_FOREACH(pw, &l2vpn->pw_list, entry) {
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) {
if (af != pw->af || ldp_addrcmp(af, &pw->addr, addr))
continue;
static struct ctl_pw pwctl;
RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree)
- LIST_FOREACH(pw, &l2vpn->pw_list, entry) {
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) {
memset(&pwctl, 0, sizeof(pwctl));
strlcpy(pwctl.l2vpn_name, pw->l2vpn->name,
sizeof(pwctl.l2vpn_name));
{
struct l2vpn_pw *pw;
- LIST_FOREACH(pw, &l2vpn->pw_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree)
ldpe_l2vpn_pw_init(pw);
}
{
struct l2vpn_pw *pw;
- LIST_FOREACH(pw, &l2vpn->pw_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree)
ldpe_l2vpn_pw_exit(pw);
}
memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn));
RB_INIT(&nl2vpn->if_tree);
- LIST_INIT(&nl2vpn->pw_list);
- LIST_INIT(&nl2vpn->pw_inactive_list);
+ RB_INIT(&nl2vpn->pw_tree);
+ RB_INIT(&nl2vpn->pw_inactive_tree);
RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn);
break;
memcpy(npw, imsg.data, sizeof(struct l2vpn_pw));
npw->l2vpn = nl2vpn;
- LIST_INSERT_HEAD(&nl2vpn->pw_list, npw, entry);
+ RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_tree, npw);
break;
case IMSG_RECONF_L2VPN_IPW:
if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL)
memcpy(npw, imsg.data, sizeof(struct l2vpn_pw));
npw->l2vpn = nl2vpn;
- LIST_INSERT_HEAD(&nl2vpn->pw_inactive_list, npw, entry);
+ RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_inactive_tree, npw);
break;
case IMSG_RECONF_END:
merge_config(ldeconf, nconf);
vty_out(vty, " member interface %s%s", lif->ifname,
VTY_NEWLINE);
- LIST_FOREACH(pw, &l2vpn->pw_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree)
ldp_l2vpn_pw_config_write(vty, pw);
- LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree)
ldp_l2vpn_pw_config_write(vty, pw);
vty_out(vty, " !%s", VTY_NEWLINE);
if (pw == NULL)
goto cancel;
- LIST_REMOVE(pw, entry);
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
free(pw);
ldp_reload(vty_conf);
return (CMD_SUCCESS);
pw = l2vpn_pw_new(l2vpn, &kif);
pw->flags = F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF;
- LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry);
+ RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
ldp_reload_ref(vty_conf, (void **)&pw);
VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE, pw);
RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif);
free(lif);
}
- while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) {
- LIST_REMOVE(pw, entry);
+ while ((pw = RB_ROOT(&l2vpn->pw_tree)) != NULL) {
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
free(pw);
}
- while ((pw = LIST_FIRST(&l2vpn->pw_inactive_list)) != NULL) {
- LIST_REMOVE(pw, entry);
+ while ((pw = RB_ROOT(&l2vpn->pw_inactive_tree)) != NULL) {
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
free(pw);
}
RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn);
pw = l2vpn_pw_new(l2vpn, &kif);
pw->flags = F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF;
- LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry);
+ RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
return (pw);
}
void
-l2vpn_pw_del_api(struct l2vpn_pw *pw)
+l2vpn_pw_del_api(struct l2vpn *l2vpn, struct l2vpn_pw *pw)
{
- LIST_REMOVE(pw, entry);
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
free(pw);
}
sizeof(*lif)) == -1)
return (-1);
}
- LIST_FOREACH(pw, &l2vpn->pw_list, entry) {
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) {
if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW, pw,
sizeof(*pw)) == -1)
return (-1);
}
- LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) {
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) {
if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW, pw,
sizeof(*pw)) == -1)
return (-1);
}
RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) {
- LIST_FOREACH(pw, &l2vpn->pw_list, entry) {
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) {
if (pw->flags & F_PW_STATIC_NBR_ADDR)
continue;
pw->af = AF_INET;
pw->addr.v4 = pw->lsr_id;
}
- LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) {
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) {
if (pw->flags & F_PW_STATIC_NBR_ADDR)
continue;
RB_FOREACH(l2vpn, l2vpn_head, &conf->l2vpn_tree) {
COPY(xl, l2vpn);
RB_INIT(&xl->if_tree);
- LIST_INIT(&xl->pw_list);
- LIST_INIT(&xl->pw_inactive_list);
+ RB_INIT(&xl->pw_tree);
+ RB_INIT(&xl->pw_inactive_tree);
RB_INSERT(l2vpn_head, &xconf->l2vpn_tree, xl);
RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) {
xf->l2vpn = xl;
RB_INSERT(l2vpn_if_head, &xl->if_tree, xf);
}
- LIST_FOREACH(pw, &l2vpn->pw_list, entry) {
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) {
COPY(xp, pw);
xp->l2vpn = xl;
- LIST_INSERT_HEAD(&xl->pw_list, xp, entry);
+ RB_INSERT(l2vpn_pw_head, &xl->pw_tree, xp);
}
- LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) {
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) {
COPY(xp, pw);
xp->l2vpn = xl;
- LIST_INSERT_HEAD(&xl->pw_inactive_list, xp, entry);
+ RB_INSERT(l2vpn_pw_head, &xl->pw_inactive_tree, xp);
}
}
#undef COPY
case PROC_MAIN:
RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree)
QOBJ_UNREG (lif);
- LIST_FOREACH(pw, &l2vpn->pw_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree)
QOBJ_UNREG (pw);
- LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry)
+ RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree)
QOBJ_UNREG (pw);
QOBJ_UNREG (l2vpn);
break;
struct l2vpn_pw *pw, *ptmp, *xp;
struct nbr *nbr;
int reset_nbr, reinstall_pwfec, reinstall_tnbr;
- LIST_HEAD(, l2vpn_pw) pw_aux_list;
+ struct l2vpn_pw_head pw_aux_list;
int previous_pw_type, previous_mtu;
previous_pw_type = l2vpn->pw_type;
}
/* merge active pseudowires */
- LIST_INIT(&pw_aux_list);
- LIST_FOREACH_SAFE(pw, &l2vpn->pw_list, entry, ptmp) {
+ RB_INIT(&pw_aux_list);
+ RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_tree, ptmp) {
/* find deleted active pseudowires */
if ((xp = l2vpn_pw_find_name(xl, pw->ifname)) == NULL) {
switch (ldpd_process) {
break;
}
- LIST_REMOVE(pw, entry);
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
free(pw);
}
}
- LIST_FOREACH_SAFE(xp, &xl->pw_list, entry, ptmp) {
+ RB_FOREACH_SAFE(xp, l2vpn_pw_head, &xl->pw_tree, ptmp) {
/* find new active pseudowires */
if ((pw = l2vpn_pw_find_name(l2vpn, xp->ifname)) == NULL) {
- LIST_REMOVE(xp, entry);
- LIST_INSERT_HEAD(&l2vpn->pw_list, xp, entry);
+ RB_REMOVE(l2vpn_pw_head, &xl->pw_tree, xp);
+ RB_INSERT(l2vpn_pw_head, &l2vpn->pw_tree, xp);
xp->l2vpn = l2vpn;
switch (ldpd_process) {
}
/* remove from active list */
- LIST_REMOVE(pw, entry);
- LIST_INSERT_HEAD(&pw_aux_list, pw, entry);
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
+ RB_INSERT(l2vpn_pw_head, &pw_aux_list, pw);
}
if (ldpd_process == PROC_LDP_ENGINE) {
l2vpn->mtu = previous_mtu;
}
- LIST_REMOVE(xp, entry);
+ RB_REMOVE(l2vpn_pw_head, &xl->pw_tree, xp);
if (ref && *ref == xp)
*ref = pw;
free(xp);
}
/* merge inactive pseudowires */
- LIST_FOREACH_SAFE(pw, &l2vpn->pw_inactive_list, entry, ptmp) {
+ RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree, ptmp) {
/* find deleted inactive pseudowires */
if ((xp = l2vpn_pw_find_name(xl, pw->ifname)) == NULL) {
- LIST_REMOVE(pw, entry);
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
if (ldpd_process == PROC_MAIN)
QOBJ_UNREG (pw);
free(pw);
}
}
- LIST_FOREACH_SAFE(xp, &xl->pw_inactive_list, entry, ptmp) {
+ RB_FOREACH_SAFE(xp, l2vpn_pw_head, &xl->pw_inactive_tree, ptmp) {
/* find new inactive pseudowires */
if ((pw = l2vpn_pw_find_name(l2vpn, xp->ifname)) == NULL) {
- LIST_REMOVE(xp, entry);
- LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, xp, entry);
+ RB_REMOVE(l2vpn_pw_head, &xl->pw_inactive_tree, xp);
+ RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, xp);
xp->l2vpn = l2vpn;
if (ldpd_process == PROC_MAIN)
QOBJ_REG (xp, l2vpn_pw);
/* check if the pseudowire should be activated */
if (pw->lsr_id.s_addr != INADDR_ANY && pw->pwid != 0) {
/* remove from inactive list */
- LIST_REMOVE(pw, entry);
- LIST_INSERT_HEAD(&l2vpn->pw_list, pw, entry);
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
+ RB_INSERT(l2vpn_pw_head, &l2vpn->pw_tree, pw);
switch (ldpd_process) {
case PROC_LDE_ENGINE:
}
}
- LIST_REMOVE(xp, entry);
+ RB_REMOVE(l2vpn_pw_head, &xl->pw_inactive_tree, xp);
if (ref && *ref == xp)
*ref = pw;
free(xp);
}
/* insert pseudowires that were disabled in the inactive list */
- LIST_FOREACH_SAFE(pw, &pw_aux_list, entry, ptmp) {
- LIST_REMOVE(pw, entry);
- LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry);
+ RB_FOREACH_SAFE(pw, l2vpn_pw_head, &pw_aux_list, ptmp) {
+ RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
+ RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
}
l2vpn->pw_type = xl->pw_type;
DECLARE_QOBJ_TYPE(l2vpn_if)
struct l2vpn_pw {
- LIST_ENTRY(l2vpn_pw) entry;
+ RB_ENTRY(l2vpn_pw) entry;
struct l2vpn *l2vpn;
struct in_addr lsr_id;
int af;
uint8_t flags;
QOBJ_FIELDS
};
+RB_HEAD(l2vpn_pw_head, l2vpn_pw);
+RB_PROTOTYPE(l2vpn_pw_head, l2vpn_pw, entry, l2vpn_pw_compare);
DECLARE_QOBJ_TYPE(l2vpn_pw)
#define F_PW_STATUSTLV_CONF 0x01 /* status tlv configured */
#define F_PW_STATUSTLV 0x02 /* status tlv negotiated */
char br_ifname[IF_NAMESIZE];
unsigned int br_ifindex;
struct l2vpn_if_head if_tree;
- LIST_HEAD(, l2vpn_pw) pw_list;
- LIST_HEAD(, l2vpn_pw) pw_inactive_list;
+ struct l2vpn_pw_head pw_tree;
+ struct l2vpn_pw_head pw_inactive_tree;
QOBJ_FIELDS
};
RB_HEAD(l2vpn_head, l2vpn);
struct l2vpn_if *lif);
struct l2vpn_pw *l2vpn_pw_new_api(struct ldpd_conf *conf,
struct l2vpn *l2vpn, const char *ifname);
-void l2vpn_pw_del_api(struct l2vpn_pw *pw);
+void l2vpn_pw_del_api(struct l2vpn *l2vpn,
+ struct l2vpn_pw *pw);
/* socket.c */
int ldp_create_socket(int, enum socket_type);
memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn));
RB_INIT(&nl2vpn->if_tree);
- LIST_INIT(&nl2vpn->pw_list);
- LIST_INIT(&nl2vpn->pw_inactive_list);
+ RB_INIT(&nl2vpn->pw_tree);
+ RB_INIT(&nl2vpn->pw_inactive_tree);
RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn);
break;
memcpy(npw, imsg.data, sizeof(struct l2vpn_pw));
npw->l2vpn = nl2vpn;
- LIST_INSERT_HEAD(&nl2vpn->pw_list, npw, entry);
+ RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_tree, npw);
break;
case IMSG_RECONF_L2VPN_IPW:
if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL)
memcpy(npw, imsg.data, sizeof(struct l2vpn_pw));
npw->l2vpn = nl2vpn;
- LIST_INSERT_HEAD(&nl2vpn->pw_inactive_list, npw, entry);
+ RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_inactive_tree, npw);
break;
case IMSG_RECONF_END:
merge_config(leconf, nconf);