Skip to content

Commit

Permalink
Merge branch 'ncm_network_nmstate_rt' into ncm_network_nmstate_rule_p…
Browse files Browse the repository at this point in the history
…aram
  • Loading branch information
Abdul Karim authored and Abdul Karim committed Jan 8, 2024
2 parents 3bf9871 + ab04411 commit 28c0265
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
28 changes: 19 additions & 9 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ sub make_nm_ip_rule
$thisrule{'route-table'} = "$routing_table_hash->{$rule->{table}}" if $rule->{table};
$thisrule{'ip-to'} = $rule->{to} if $rule->{to};
$thisrule{'ip-from'} = $rule->{from} if $rule->{from};
$thisrule{'action'} = $rule->{nmstate-action} if $rule->{nmstate-action};
$thisrule{'state'} = $rule->{nmstate-state} if $rule->{nmstate-state};
$thisrule{'iff'} = $rule->{nmstate-iff} if $rule->{nmstate-iff};
$thisrule{'fwmark'} = $rule->{nmstate-fwmark} if $rule->{nmstate-fwmark};
$thisrule{'fwmask'} = $rule->{nmstate-fwmask} if $rule->{nmstate-fwmask};
$thisrule{'action'} = $rule->{'nmstate-action'} if $rule->{'nmstate-action'};
$thisrule{'state'} = $rule->{'nmstate-state'} if $rule->{'nmstate-state'};
$thisrule{'iff'} = $rule->{'nmstate-iff'} if $rule->{'nmstate-iff'};
$thisrule{'fwmark'} = $rule->{'nmstate-fwmark'} if $rule->{'nmstate-fwmark'};
$thisrule{'fwmask'} = $rule->{'nmstate-fwmask'} if $rule->{'nmstate-fwmask'};
push (@rule_entry, \%thisrule);

# Add a default absent rule to match table defined. This will clear any existing rules for this table, instead of merging.
Expand Down Expand Up @@ -172,6 +172,16 @@ sub make_nm_ip_route
return \@rt_entry;
}

# create an absent route entry.
# if you prepend the routes with the 'absent', then nmstate will clear the existing matches and apply the routes
# This will allow nmstate to clear all routes for the interface and only apply routes defined in config.
# useful when routes are changed later on in profile once host is built.
# return arrayref
sub make_nm_route_absent {
my ($self, $device) = @_;
return { 'state' => 'absent', 'next-hop-interface' => $device };
}

# group all eth bound to a bond together in a hashref for to be used as
# - port in nmstate config file
sub get_bonded_eth
Expand Down Expand Up @@ -390,13 +400,13 @@ sub generate_nmstate_config
# next-hop-interface:
# and so on.
my $routes = [];
push @$routes, ($self->make_nm_route_absent($name));
push @$routes, \%default_rt if scalar %default_rt;
if (defined($iface->{route})) {
$self->verbose("policy route found, nmstate will manage it");
my $route = $iface->{route};
$routes = $self->make_nm_ip_route($name, $route, $routing_table);
push @$routes, \%default_rt if scalar %default_rt;
} elsif (scalar %default_rt){
push @$routes, \%default_rt if scalar %default_rt;
my $policyroutes = $self->make_nm_ip_route($name, $route, $routing_table);
push @$routes, @{$policyroutes};
}

my $policy_rule = [];
Expand Down
4 changes: 4 additions & 0 deletions ncm-network/src/test/perl/nmstate_simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ interfaces:
name: eth0
profile-name: eth0
type: bond
routes:
config:
- next-hop-interface: eth0
state: absent
EOF

Readonly my $NOTTOREMOVE => <<EOF;
Expand Down

0 comments on commit 28c0265

Please sign in to comment.