Skip to content

Commit

Permalink
ncm-network: nmstate support for configuring dummy interfaces
Browse files Browse the repository at this point in the history
support for configuring dummy interfaces using nmstate module.
only if manage_vips is set.
  • Loading branch information
Abdul Karim authored and Abdul Karim committed Aug 9, 2023
1 parent 5a300ec commit daf451f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
20 changes: 20 additions & 0 deletions ncm-network/src/main/pan/components/network/core-schema.pan
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ type structure_interface_alias = {
"fqdn" ? type_fqdn
};


############################################################
#
# Defines virtual IP addresses as loopback interface
#
############################################################
@documentation{
Define vip interfaces for configuring loopback interface. Used with frr/zebra configuration
}

type structure_vip = {
"interfaces" : valid_interface[]
"ip" : type_ip
"fqdn" ? string
"netmask" ? type_ip
"broadcast" ? type_ip
};

@documentation{
Describes the bonding options for configuring channel bonding on EL5 and similar.
}
Expand Down Expand Up @@ -423,6 +441,8 @@ type structure_network = {
"primary_ip" ? string
"routers" ? structure_router{}
"ipv6" ? structure_ipv6
"manage_vip" : boolean = false
"vips" ? structure_vip{}
@{Manage custom routing table entries; key is the name; value is the id}
"routing_table" ? long(1..252){} with {
if (exists(SELF['main']) || exists(SELF['local']) || exists(SELF['default']) || exists(SELF['unspec'])) {
Expand Down
44 changes: 43 additions & 1 deletion ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,34 @@ sub nmstate_file_dump
}
}

# given ip/netmask address return cidr mask length
sub get_masklen {
my ($self, $ip_netmask) = @_;
$self->verbose("Converting $ip_netmask to cidr notation");
my $ip = NetAddr::IP->new($ip_netmask);
return $ip->masklen;
}

# generate dummy interface config (aka loopback) for all service address vip
# return hashrefs needed by nmstate interface config
sub generate_vip_config {
my ($self, $iface_name, $vip) = @_;
my %dummy_iface;
my $ip_list = {};
my $netmask = $vip->{netmask} || "255.255.255.255";
my $ip = $vip->{ip};
$ip_list->{ip} = $ip;
$ip_list->{'prefix-length'} = get_masklen($self, "$ip/$netmask");
$dummy_iface{name} = $iface_name;
$dummy_iface{'profile-name'} = $iface_name;
$dummy_iface{type} = "dummy";
$dummy_iface{state} = "up";
$dummy_iface{ipv4}->{enabled} = "true";
$dummy_iface{ipv4}->{address} = [$ip_list];
my $iface_cfg->{'interfaces'} = [\%dummy_iface];
return $iface_cfg;
}

# generates the hashrefs for interface in yaml file format needed by nmstate.
# bulk of the config settings needed by the nmstate yml is done here.
# to add additional options, it should be constructed here.
Expand Down Expand Up @@ -424,7 +452,6 @@ sub is_active_interface
my $found = 0;
foreach my $conn_name (@existing_conn) {
my ($name, $dev) = split(':', $conn_name);
# trim
if ("$dev" eq "$ifacename") {
# ncm-network will set connection same as interface name, if this doesn't match,
# it means this connection existed before nmstate did its first apply.
Expand Down Expand Up @@ -583,6 +610,21 @@ sub Configure
$self->ethtool_opts_keeps_state($file_name, $ifacename, $iface, $exifiles);
}

# configure vips defined under path /system/network/vips/ as dummy interface
# only if manage_vips is set to true.
my $vips = $net->{vips};
if (($vips) && ($net->{manage_vips})) {
$self->verbose("Service address vips found, configuring dummy interfaces");
my $idx = 0;
foreach my $name (sort keys %$vips) {
my $dummy_name="dummy$idx";
my $nmstate_dummy_cfg = $self->generate_vip_config($dummy_name, $vips->{$name});
my $dummy_filename = $self->iface_filename($dummy_name);
$exifiles->{$dummy_filename} = $self->nmstate_file_dump($dummy_filename, $nmstate_dummy_cfg);
$idx++;
}
};

my $dev2mac = $self->make_dev2mac();

# We now have a map with files and values.
Expand Down

0 comments on commit daf451f

Please sign in to comment.