Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package/mcd/mcd.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sha256 63e70c0bd457b1d198acdb8d2bbe4925140ed368c7b3971a02f6c969058c039c mcd-1.0.tar.gz
sha256 834f45ed282fd010f354ecc0a50538af519a1cfcc4d2866de3be06982fa9ed29 LICENSE
sha256 318b3adb8fa5bcc119758194d3f1cdb2d2b38db935f72f4cfe629158d31a05a5 mcd-2.0.tar.gz
sha256 99a0480db163445c5a1a5bf7f85bc37cbb5be8c40e9e441291ad78e8d4252d0b LICENSE
6 changes: 3 additions & 3 deletions package/mcd/mcd.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#
################################################################################

MCD_VERSION = 1.0
MCD_VERSION = 2.0
MCD_SITE = https://github.com/kernelkit/mcd/releases/download/v$(MCD_VERSION)
MCD_LICENSE = BSD-3-Clause
MCD_LICENSE_FILES = LICENSE

define MCD_INSTALL_CONFIG
$(INSTALL) -D -m 0644 $(MCD_PKGDIR)/example.conf \
$(TARGET_DIR)/etc/mcd/example.conf
$(INSTALL) -D -m 0644 $(@D)/mcd.conf $(TARGET_DIR)/etc/mcd.conf
$(INSTALL) -d -m 0755 $(TARGET_DIR)/etc/mc.d
endef
MCD_POST_INSTALL_TARGET_HOOKS += MCD_INSTALL_CONFIG

Expand Down
2 changes: 1 addition & 1 deletion package/mcd/mcd.svc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
service [2345789] env:-/etc/default/mcd /usr/sbin/mcd -sn $MCD_ARGS -- Multicast querier daemon
service [2345] env:-/etc/default/mcd mcd -sn $MCD_ARGS -- Multicast querier daemon
141 changes: 116 additions & 25 deletions src/confd/src/ietf-interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,57 @@ static int netdag_gen_ethtool(struct dagger *net, struct lyd_node *cif, struct l
return 0;
}

static void brport_pvid_adjust(FILE *br, struct lyd_node *vlan, int vid, const char *brport,
struct lydx_diff *pvidiff, int tagged)
{
const char *type = tagged ? "tagged" : "untagged";
struct lyd_node *port;

LYX_LIST_FOR_EACH(lyd_child(vlan), port, type) {
if (strcmp(brport, lyd_get_value(port)))
continue;

if (pvidiff->old && atoi(pvidiff->old) == vid)
fprintf(br, "vlan add vid %d dev %s %s\n", vid, brport, type);
if (pvidiff->new && atoi(pvidiff->new) == vid)
fprintf(br, "vlan add vid %d dev %s pvid %s\n", vid, brport, type);
}
}

/*
* Called when only pvid is changed for a bridge-port. Then we use the
* cif data to iterate over all known VLANS for the given port.
*/
static int bridge_port_vlans(struct dagger *net, struct lyd_node *cif, const char *brname,
const char *brport, struct lydx_diff *pvidiff)
{
struct lyd_node *bridge = lydx_find_by_name(lyd_parent(cif), "interface", brname);
struct lyd_node *vlan, *vlans;
int err = 0;
FILE *br;

vlans = lydx_get_descendant(lyd_child(bridge), "bridge", "vlans", NULL);
if (!vlans)
goto done;

br = dagger_fopen_next(net, "init", brname, 60, "init.bridge");
if (!br) {
err = -EIO;
goto done;
}

LYX_LIST_FOR_EACH(lyd_child(vlans), vlan, "vlan") {
int vid = atoi(lydx_get_cattr(vlan, "vid"));

brport_pvid_adjust(br, vlan, vid, brport, pvidiff, 0);
brport_pvid_adjust(br, vlan, vid, brport, pvidiff, 1);
}

fclose(br);
done:
return err;
}

static int bridge_diff_vlan_port(struct dagger *net, FILE *br, const char *brname, int vid,
const char *brport, int tagged, enum lydx_op op)
{
Expand Down Expand Up @@ -877,20 +928,52 @@ static void bridge_port_settings(FILE *next, const char *ifname, struct lyd_node

static int bridge_gen_ports(struct dagger *net, struct lyd_node *dif, struct lyd_node *cif, FILE *ip)
{
const char *ifname = lydx_get_cattr(cif, "name");
struct lyd_node *node, *bridge;
struct lydx_diff brdiff;
const char *ifname;
int err = 0;

if (!is_bridge_port(cif))
return 0;

node = lydx_get_descendant(lyd_child(dif), "bridge-port", NULL);
if (!node)
goto fail;

/*
* If bridge is not in dif, then we only have bridge-port
* settings and can use cif instead for any new settings
* since we always set *all* port settings anyway.
*/
bridge = lydx_get_child(node, "bridge");
if (!node || !bridge)
return 0; /* bridge port but no diff, skip */
if (!bridge) {
struct lyd_node *pvid = lydx_get_child(node, "pvid");
struct lydx_diff pvidiff;
const char *brname;
FILE *next;

ifname = lydx_get_cattr(cif, "name");
node = lydx_get_descendant(lyd_child(cif), "bridge-port", NULL);
brname = lydx_get_cattr(node, "bridge");
if (!node || !brname)
goto fail;

next = dagger_fopen_next(net, "init", ifname, 56, "init.ip");
if (!next) {
err = -EIO;
goto fail;
}
bridge_port_settings(next, ifname, cif);
fclose(next);

/* Change in bridge port's PVID => change in VLAN port memberships */
if (lydx_get_diff(pvid, &pvidiff))
bridge_port_vlans(net, cif, brname, ifname, &pvidiff);

err = dagger_add_dep(net, brname, ifname);
if (err)
return ERR_IFACE(cif, err, "Unable to add dep \"%s\" to %s", ifname, brdiff);
goto fail;
}

if (lydx_get_diff(bridge, &brdiff) && brdiff.old) {
FILE *prev;
Expand Down Expand Up @@ -972,28 +1055,31 @@ static int querier_mode(const char *mode)
return 0; /* unknown: off */
}

static void mcast_querier(const char *ifname, int mode, int interval)
static void mcast_querier(const char *ifname, int vid, int mode, int interval)
{
FILE *fp;

DEBUG("mcast querier %s mode %d interval %d", ifname, mode, interval);
if (!mode) {
erasef("/etc/mcd/%s.conf", ifname);
systemf("initctl -bnq disable mcd@%s", ifname);
systemf("rm -f /etc/mc.d/%s-*.conf", ifname);
systemf("initctl -bnq disable mcd");
return;
}

fp = fopenf("w", "/etc/mcd/%s.conf", ifname);
fp = fopenf("w", "/etc/mc.d/%s-%d.conf", ifname, vid);
if (!fp) {
ERRNO("Failed creating querier configuration for %s", ifname);
return;
}

fprintf(fp, "query-interval %d\n", interval);
fprintf(fp, "iface %s enable %sigmpv3\n", ifname, mode == 1 ? "proxy-queries " : "");
fprintf(fp, "iface %s", ifname);
if (vid > 0)
fprintf(fp, " vlan %d", vid);
fprintf(fp, " enable %sigmpv3 query-interval %d\n",
mode == 1 ? "proxy-queries " : "", interval);
fclose(fp);

systemf("initctl -bnq enable mcd@%s", ifname);
systemf("initctl -bnq enable mcd");
}

static char *find_vlan_interface(sr_session_ctx_t *session, const char *brname, int vid)
Expand Down Expand Up @@ -1023,7 +1109,8 @@ static char *find_vlan_interface(sr_session_ctx_t *session, const char *brname,
return NULL;
}

static int vlan_mcast_settings(sr_session_ctx_t *session, FILE *br, const char *brname, struct lyd_node *vlan, int vid)
static int vlan_mcast_settings(sr_session_ctx_t *session, FILE *br, const char *brname,
struct lyd_node *vlan, int vid)
{
int interval, querier, snooping;
struct lyd_node *mcast;
Expand All @@ -1036,18 +1123,15 @@ static int vlan_mcast_settings(sr_session_ctx_t *session, FILE *br, const char *
snooping = lydx_is_enabled(mcast, "snooping");
querier = querier_mode(lydx_get_cattr(mcast, "querier"));

fprintf(br, "vlan global set vid %d dev %s mcast_snooping %d",
fprintf(br, "vlan global set vid %d dev %s mcast_snooping %d\n",
vid, brname, snooping);

interval = atoi(lydx_get_cattr(mcast, "query-interval"));
ifname = find_vlan_interface(session, brname, vid);
if (ifname)
mcast_querier(ifname, querier, interval);
fprintf(br, " mcast_querier %d mcast_query_interval %d",
ifname ? 0 : querier, interval * 100);

/* XXX: make configurable later */
fprintf(br, " mcast_igmp_version 3 mcast_mld_version 2\n");
mcast_querier(ifname, 0, querier, interval);
else
mcast_querier(brname, vid, querier, interval);

return 0;
}
Expand All @@ -1059,7 +1143,7 @@ static int bridge_mcast_settings(FILE *ip, const char *brname, struct lyd_node *

mcast = lydx_get_descendant(lyd_child(cif), "bridge", "multicast", NULL);
if (!mcast) {
mcast_querier(brname, 0, 0);
mcast_querier(brname, 0, 0, 0);
return 0;
}

Expand All @@ -1072,11 +1156,10 @@ static int bridge_mcast_settings(FILE *ip, const char *brname, struct lyd_node *
interval = atoi(lydx_get_cattr(mcast, "query-interval"));
fprintf(ip, " mcast_query_interval %d", interval * 100);

DEBUG("%s: querier %d", brname, vlan_filtering ? -1 : querier);
if (!vlan_filtering)
mcast_querier(brname, querier, interval);
mcast_querier(brname, 0, querier, interval);
else
mcast_querier(brname, 0, 0);
mcast_querier(brname, 0, 0, 0);

return 0;
}
Expand Down Expand Up @@ -1142,8 +1225,16 @@ static int netdag_gen_bridge(sr_session_ctx_t *session, struct dagger *net, stru
err = bridge_diff_vlan_ports(net, br, brname, vid, vlan, 1);
if (err)
break;
}

/* need the vlans created before we can set features on them */
vlans = lydx_get_descendant(lyd_child(cif), "bridge", "vlans", NULL);
if (!vlans)
goto done;

LYX_LIST_FOR_EACH(lyd_child(vlans), vlan, "vlan") {
int vid = atoi(lydx_get_cattr(vlan, "vid"));

/* need the vlans created before we can set features on them */
err = vlan_mcast_settings(session, br, brname, vlan, vid);
if (err)
break;
Expand Down Expand Up @@ -1324,7 +1415,7 @@ static int netdag_gen_iface_del(struct dagger *net, struct lyd_node *dif,

DEBUG_IFACE(dif, "");

mcast_querier(ifname, 0, 0);
mcast_querier(ifname, 0, 0, 0);
if (dagger_should_skip_current(net, ifname))
return 0;

Expand Down
6 changes: 5 additions & 1 deletion src/klish-plugin-infix/xml/infix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
</COMMAND>
</SWITCH>
</COMMAND>
<COMMAND name="detailed" help="Show VLAN table">
<COMMAND name="vlan" help="Show VLAN table">
<ACTION sym="script">bridge -color vlan</ACTION>
<SWITCH name="optional" min="0">
<COMMAND name="detailed" help="Detailed (full) output">
Expand Down Expand Up @@ -366,6 +366,10 @@
<COMMAND name="detailed" help="Detailed (full) output" mode="switch">
<ACTION sym="script">ip -color -d addr</ACTION>
</COMMAND>

<COMMAND name="multicast" help="Show IGMP/MLD status" mode="switch">
<ACTION sym="script">mctl</ACTION>
</COMMAND>
</SWITCH>
</COMMAND>

Expand Down
18 changes: 18 additions & 0 deletions src/libsrx/src/lyx.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...)
return node;
}

/*
* Similar to lydx_get_decsendant() but for, e.g., finding a named
* interface in ietf-interfaces from the top node.
*/
struct lyd_node *lydx_find_by_name(struct lyd_node *from, const char *by, const char *name)
{
struct lyd_node *node;

LY_LIST_FOR(lydx_get_sibling(lyd_child(from), by), node) {
if (strcmp(lydx_get_cattr(node, "name"), name))
continue;

return node;
}

return NULL;
}

const char *lydx_get_mattr(struct lyd_node *node, const char *name)
{
struct lyd_meta *meta;
Expand Down
1 change: 1 addition & 0 deletions src/libsrx/src/lyx.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bool lydx_get_diff(struct lyd_node *node, struct lydx_diff *nd);
struct lyd_node *lydx_get_sibling(struct lyd_node *sibling, const char *name);
struct lyd_node *lydx_get_child(struct lyd_node *parent, const char *name);
struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...);
struct lyd_node *lydx_find_by_name(struct lyd_node *from, const char *by, const char *name);

const char *lydx_get_mattr(struct lyd_node *node, const char *name);
const char *lydx_get_attr(struct lyd_node *sibling, const char *name);
Expand Down