Skip to content

proxy: one uplink membership per group, aggregated over all downlinks - #29

Open
kristofer84 wants to merge 2 commits into
openwrt:masterfrom
kristofer84:uplink-aggregate
Open

kristofer84 wants to merge 2 commits into
openwrt:masterfrom
kristofer84:uplink-aggregate

Conversation

@kristofer84

Copy link
Copy Markdown

Fixes #14.

Each downlink kept its own upstream membership (struct client inside
struct proxy_downlink), and every update passed through MCAST_LEAVE_GROUP
first, so a second downlink asking for the same group ended the stream for both.

  • proxy: one client per proxy; the uplink filter is recomputed over all
    downlinks (EXCLUDE with the intersection of the exception lists, INCLUDE with
    the union, EXCLUDE(X\A) subtraction, "any source" when a downlink asks for it).
  • client: join / update / leave split apart. A changed filter is applied with
    MCAST_MSFILTER; MCAST_LEAVE_GROUP is sent only when the last listener goes.
  • querier: unlink a group before the update callback, so the last listener is
    not mistaken for an empty filter.

Verified in a netns harness (one uplink, two downlinks, fake IGMPv2 access node):
two downlinks on one group go from 2 upstream memberships to 1, and a second viewer
joining on the other downlink no longer emits a leave - the existing viewer's worst
gap drops from 2.02 s to 0.04 s. Also on a live OpenWrt 25.12.6 gateway with an ISP
IPTV feed: one HD channel served to two downlinks, 19 Mbit/s on the uplink with
19 Mbit/s forwarded to each, no leave on join or on roaming between APs.

Every downlink owned its own client socket on the uplink, so each downlink
kept its own kernel membership for a group and could drop it while another
downlink still had listeners. RFC 4605 asks for one upstream membership per
(uplink, group), computed from the listener state of all downlinks of that
proxy.

proxy_trigger() now recomputes the aggregate for the group over every
downlink and hands it to client_set() once:

- an EXCLUDE downlink makes the aggregate EXCLUDE with the intersection of
  the exception lists (RFC 4605 3.2.2). A downlink that asks for any source
  (ASM, or an IGMPv1/v2 reporter, which RFC 3376 7.2.1 records as EXCLUDE
  without sources) empties the list.
- otherwise INCLUDE with the union of the include lists.
- a source an INCLUDE downlink wants is removed from the EXCLUDE
  intersection, so the result is the exact union of all downlinks' receive
  sets rather than only the intersection of the exceptions.

This relies on querier_detach() already unlinking the user from
proxy->querier before it announces its groups: a downlink being removed is
out of the tree by then, so the aggregate of the remaining downlinks is what
gets applied, and proxy_remove_downlink() needs no extra call.

The scope of a group is now matched against the proxy's flags inside
proxy_update_group() instead of a downlink's flags in proxy_trigger().
proxy_set() sets a downlink's flags only after querier_attach(), so every
group that attach announced was treated as in scope and joined on the
uplink, while its later leave was filtered out. The per-downlink flags field
goes away with it.

The filter last given to the kernel is cached per group. client_set() begins
with MCAST_LEAVE_GROUP, so re-applying an unchanged aggregate would put a
leave on the uplink for every downlink event. With the cache client_set()
runs only when the aggregate actually changes; it is not recorded when the
call fails, so a failed call is retried.

Verified: builds with gcc 14.2.0 and -Wall -Wextra -Werror without warnings.
In a netns harness (two downlink veths, one uplink, fake IGMPv2 ISP) a group
held by two downlinks has one kernel membership instead of two, and
client_set() runs twice per group (join, last leave) instead of four times;
the single-downlink case is unchanged on the wire.

Signed-off-by: Kristofer Nilsson <kristofer.nilsson@outlook.com>
client_set() began every call with MCAST_LEAVE_GROUP, so any change of the
aggregate put an IGMP/MLD leave on the uplink before the new filter was
applied. An access node stops the stream on that leave and needs a fresh join
cycle, so a viewer that was already playing lost the picture when a second
downlink started the same group: the field result was "the new viewer plays,
the existing one stops".

Split the operation into client_join(), client_update() and client_leave().
An update applies MCAST_MSFILTER alone: per RFC 3678 it replaces the source
filter of a membership that exists, so the uplink never sees the group go
away when only the filter changes. A failed update leaves the previous filter
in place, which is what the caller still has recorded, so it needs no undo.
The proxy tracks in proxy->applied which filter the kernel holds for a group,
and an entry exists only while the group is joined, so a join, an update and
the final leave are distinguishable without asking the kernel.

A join that fails half way is rolled back: client_join() drops the membership
again when MCAST_MSFILTER is rejected after MCAST_JOIN_GROUP succeeded. That
happens when the union of the downlinks' sources exceeds igmp_max_msf
(default 10). Without the rollback the caller would neither record the
membership nor be able to leave it later, and every following event would try
to join it again and fail with EADDRINUSE.

INCLUDE without sources is the "no sources wanted" state of RFC 3376 and
RFC 3810, so proxy_downlink_state() reports such a downlink as having no
listeners for the group. It shows up when the last listener leaves and after
a TO_IN with an empty source list; joining the group for it would create an
upstream membership nobody asked for, and for an SSM group an EXCLUDE join,
which RFC 4607 does not allow. EXCLUDE without exceptions keeps meaning any
source.

For the same reason a group that is gone has to differ from a downlink that
wants nothing, so querier_remove_group() unlinks the group from the tree
before it notifies.

proxy_aggregate() reads each downlink's state once into a snapshot, so its
passes over the states do not repeat the group lookups.

Verified: gcc 14.2.0 with -Wall -Wextra -Werror, no warnings. In the netns
harness (one uplink, two downlink veths, fake IGMPv2 access node that stops
the feed on a leave and resumes 2 s after the next join) a source-filtered
viewer and an any-source viewer of the same group on different downlinks: the
previous commit leaves the group on the uplink three times, at the newcomer's
join, when its state expires and for the last listener, and the first viewer
stalls for 2.0 s; this commit sends MSFILTER updates only, sends one leave
when the last listener goes, and the longest gap is 0.098 s. A v3 reporter
sending TO_IN with no sources for an unwatched group makes this commit do
nothing, where the previous one joined and left the group twice.

Signed-off-by: Kristofer Nilsson <kristofer.nilsson@outlook.com>
@kristofer84

Copy link
Copy Markdown
Author

Reworked after review - both issues are fixed in the current push:

  • client_join(): if MCAST_MSFILTER fails after MCAST_JOIN_GROUP succeeded, it now drops the membership before returning, so a rejected filter cannot leave an untracked any-source join (reachable with igmp_max_msf=10 against a union of up to 75 sources per downlink). client_update() needs no undo - a failed update leaves the previous filter, which is what is recorded.
  • proxy_downlink_state(): INCLUDE with no sources now means no listeners, not any-source. EXCLUDE{} still means any source. This removes the spurious upstream join/leave that a stray TO_IN({}) used to cause, and avoids an invalid EXCLUDE join for an SSM group.

Also: the scope check now runs against the proxy's flags inside proxy_update_group() (downlink flags were set after querier_attach(), so the initial announcements matched everything), proxy_aggregate() snapshots each downlink's state once, and the author/SoB are the submitter's real name with one line per commit.

Harness: two downlinks on one group - 1 upstream membership throughout, 1 leave (the last-listener one), worst gap 0.036 s at the join. A v3 TO_IN({}) for an unwatched group now produces no proxy operation at all (previously a join+leave pair). Live check on OpenWrt 25.12.6 with an ISP feed: one HD channel to two downlinks, 19 Mbit/s on the uplink and 19 to each downlink, no leave on join or roam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regarding the issue of omcproxy in a multi-LAN network environment

1 participant