MT#55283 support interface aliases

Change-Id: Ifd85bc49201bab1ab89a8d240ee682a6d1655868
rfuchs/dataport
Richard Fuchs 2 years ago
parent 3e73fb5181
commit a008e27a45

@ -276,11 +276,20 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) {
struct intf_config *ifa; struct intf_config *ifa;
/* name */ /* name */
c = strchr(s, '/'); c = strpbrk(s, "/=");
if (c) { if (c) {
char cc = *c;
*c++ = 0; *c++ = 0;
str_init(&name, s); str_init(&name, s);
s = c; 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 else
str_init(&name, "default"); 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)); gptr_data = g_slice_alloc0(sizeof(*gptr_data));
memcpy(gptr_data, l->data, 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->name, &l->data->name);
str_init_dup_str(&gptr_data->alias, &l->data->alias);
t_queue_push_tail(&ini_rtpe_cfg->interfaces, gptr_data); 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) { static void free_config_interfaces(struct intf_config *i) {
str_free_dup(&i->name); str_free_dup(&i->name);
str_free_dup(&i->alias);
g_slice_free1(sizeof(*i), i); g_slice_free1(sizeof(*i), i);
} }

@ -779,7 +779,25 @@ static void __interface_append(struct intf_config *ifa, sockfamily_t *fam, bool
lif = __get_logical_interface(&ifa->name, fam); lif = __get_logical_interface(&ifa->name, fam);
if (!lif) { 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; return;
lif = g_slice_alloc0(sizeof(*lif)); lif = g_slice_alloc0(sizeof(*lif));

@ -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 round-robin algorithm is used and will select interfaces with the
same *BASE* name. 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 ### Legacy Protocols
If you are not using the NG protocol but rather the legacy UDP protocol If you are not using the NG protocol but rather the legacy UDP protocol

@ -97,6 +97,7 @@ struct intf_config {
str name; // full name (before the '/' separator in config) str name; // full name (before the '/' separator in config)
str name_base; // if name is "foo:bar", this is "foo" str name_base; // if name is "foo:bar", this is "foo"
str name_rr_spec; // if name is "foo:bar", this is "bar" 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 local_address;
struct intf_address advertised_address; struct intf_address advertised_address;
unsigned int port_min, port_max; unsigned int port_min, port_max;

@ -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 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 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)) -n 2223 -c 12345 -f -L 7 -E -u 2222 --silence-detect=1))
or die; or die;
@ -170,4 +171,75 @@ SDP
offer('intfs selection alias', { direction => [qw(blah baz)] }, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio 2000 RTP/AVP 0
c=IN IP4 198.51.100.1
a=sendrecv
----------------------------------
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.2
a=rtpmap:0 PCMU/8000
a=sendrecv
a=rtcp:PORT
SDP
answer('intfs selection alias', { }, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.2
s=tester
t=0 0
m=audio 3000 RTP/AVP 0
c=IN IP4 198.51.100.2
a=sendrecv
----------------------------------
v=0
o=- 1545997027 1 IN IP4 198.51.100.2
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
a=rtpmap:0 PCMU/8000
a=sendrecv
a=rtcp:PORT
SDP
offer('intfs selection and new stream', { }, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio 2000 RTP/AVP 0
c=IN IP4 198.51.100.1
a=sendrecv
m=audio 2004 RTP/AVP 0
c=IN IP4 198.51.100.1
a=sendrecv
----------------------------------
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.2
a=rtpmap:0 PCMU/8000
a=sendrecv
a=rtcp:PORT
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.2
a=rtpmap:0 PCMU/8000
a=sendrecv
a=rtcp:PORT
SDP
done_testing(); done_testing();

Loading…
Cancel
Save