diff --git a/daemon/main.c b/daemon/main.c index 8b0240190..fa1e28529 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -276,11 +276,20 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) { struct intf_config *ifa; /* name */ - c = strchr(s, '/'); + c = strpbrk(s, "/="); if (c) { + char cc = *c; *c++ = 0; str_init(&name, s); s = c; + if (cc == '=') { + // foo=bar + ifa = g_slice_alloc0(sizeof(*ifa)); + str_init_dup_str(&ifa->name, &name); + str_init_dup(&ifa->alias, s); + t_queue_push_tail(q, ifa); + return 0; + } } else str_init(&name, "default"); @@ -1073,6 +1082,7 @@ static void fill_initial_rtpe_cfg(struct rtpengine_config* ini_rtpe_cfg) { gptr_data = g_slice_alloc0(sizeof(*gptr_data)); memcpy(gptr_data, l->data, sizeof(*gptr_data)); str_init_dup_str(&gptr_data->name, &l->data->name); + str_init_dup_str(&gptr_data->alias, &l->data->alias); t_queue_push_tail(&ini_rtpe_cfg->interfaces, gptr_data); } @@ -1148,6 +1158,7 @@ static void fill_initial_rtpe_cfg(struct rtpengine_config* ini_rtpe_cfg) { static void free_config_interfaces(struct intf_config *i) { str_free_dup(&i->name); + str_free_dup(&i->alias); g_slice_free1(sizeof(*i), i); } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 0b0312921..9191d16c1 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -779,7 +779,25 @@ static void __interface_append(struct intf_config *ifa, sockfamily_t *fam, bool lif = __get_logical_interface(&ifa->name, fam); if (!lif) { - if (!create) + if (!create) { + // alias? + if (!ifa->alias.len) + return; + + struct logical_intf *alias = __get_logical_interface(&ifa->alias, fam); + if (!alias) + return; + + struct intf_key *key = g_new0(__typeof(*key), 1); + key->name = ifa->name; + key->preferred_family = fam; + + t_hash_table_insert(__logical_intf_name_family_hash, key, alias); + + return; + } + + if (ifa->alias.len) // handled in second run return; lif = g_slice_alloc0(sizeof(*lif)); diff --git a/docs/rtpengine.md b/docs/rtpengine.md index 969456752..266689fd8 100644 --- a/docs/rtpengine.md +++ b/docs/rtpengine.md @@ -1466,6 +1466,23 @@ If the first given interface has the *BASE:SUFFIX* format then the round-robin algorithm is used and will select interfaces with the same *BASE* name. +### Alias Names + +Interface alias names can be created using the *ALIAS=NAME* syntax. The alias +must be listed after the primary interface that it references. For example, to +create an actual logical interface *pub1* and then an alias *pub* for that +interface: + + interface = pub1/IPv4 pub=pub1 + +Interface aliases are useful in combination with Redis replication. If an +interface is referred to via an alias name (e.g. *direction=pub*), then the +interface's actual name (*pub1* in this example) is propagated into the Redis +storage and thus to any dependent standby instances. These standby instances +can then have different address configurations for that interface, which makes +it possible to facilitate failover with static addressing (for example behind +an IP load balancer). + ### Legacy Protocols If you are not using the NG protocol but rather the legacy UDP protocol diff --git a/include/media_socket.h b/include/media_socket.h index fb1ddde98..72cdc3656 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -97,6 +97,7 @@ struct intf_config { str name; // full name (before the '/' separator in config) str name_base; // if name is "foo:bar", this is "foo" str name_rr_spec; // if name is "foo:bar", this is "bar" + str alias; // if interface is "foo=bar", this is "bar" struct intf_address local_address; struct intf_address advertised_address; unsigned int port_min, port_max; diff --git a/t/auto-daemon-tests-intfs.pl b/t/auto-daemon-tests-intfs.pl index 4cd18e643..f747d82b8 100644 --- a/t/auto-daemon-tests-intfs.pl +++ b/t/auto-daemon-tests-intfs.pl @@ -11,6 +11,7 @@ use POSIX; autotest_start(qw(--config-file=none -t -1 -i foo/203.0.113.1 -i foo/2001:db8:4321::1 -i bar/203.0.113.2 -i bar/2001:db8:4321::2 + -i blah=foo -i baz=bar -n 2223 -c 12345 -f -L 7 -E -u 2222 --silence-detect=1)) or die; @@ -170,4 +171,75 @@ SDP +offer('intfs selection alias', { direction => [qw(blah baz)] }, <