-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
532 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2019-2023 The Liqo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package firewall | ||
|
||
import ( | ||
"github.com/google/nftables" | ||
|
||
firewallapi "github.com/liqotech/liqo/apis/networking/v1alpha1/firewall" | ||
) | ||
|
||
func addChain(nftconn *nftables.Conn, chain *firewallapi.Chain, table *nftables.Table) { | ||
nftChain := &nftables.Chain{Table: table} | ||
setChainName(nftChain, chain.Name) | ||
setHooknum(nftChain, chain.Hook) | ||
setPriority(nftChain, chain.Priority) | ||
setType(nftChain, chain.Type) | ||
setPolicy(nftChain, chain.Policy) | ||
nftconn.AddChain(nftChain) | ||
} | ||
|
||
func setChainName(chain *nftables.Chain, name string) { | ||
chain.Name = name | ||
} | ||
|
||
func setHooknum(chain *nftables.Chain, hooknum firewallapi.ChainHook) { | ||
switch hooknum { | ||
case firewallapi.ChainHookPrerouting: | ||
chain.Hooknum = nftables.ChainHookPrerouting | ||
case firewallapi.ChainHookInput: | ||
chain.Hooknum = nftables.ChainHookInput | ||
case firewallapi.ChainHookForward: | ||
chain.Hooknum = nftables.ChainHookForward | ||
case firewallapi.ChainHookOutput: | ||
chain.Hooknum = nftables.ChainHookOutput | ||
case firewallapi.ChainHookPostrouting: | ||
chain.Hooknum = nftables.ChainHookPostrouting | ||
case firewallapi.ChainHookIngress: | ||
chain.Hooknum = nftables.ChainHookIngress | ||
} | ||
} | ||
|
||
func setPriority(chain *nftables.Chain, priority firewallapi.ChainPriority) { | ||
switch priority { | ||
case firewallapi.ChainPriorityFirst: | ||
chain.Priority = nftables.ChainPriorityFirst | ||
case firewallapi.ChainPriorityConntrackDefrag: | ||
chain.Priority = nftables.ChainPriorityConntrackDefrag | ||
case firewallapi.ChainPriorityRaw: | ||
chain.Priority = nftables.ChainPriorityRaw | ||
case firewallapi.ChainPrioritySELinuxFirst: | ||
chain.Priority = nftables.ChainPrioritySELinuxFirst | ||
case firewallapi.ChainPriorityConntrack: | ||
chain.Priority = nftables.ChainPriorityConntrack | ||
case firewallapi.ChainPriorityMangle: | ||
chain.Priority = nftables.ChainPriorityMangle | ||
case firewallapi.ChainPriorityNATDest: | ||
chain.Priority = nftables.ChainPriorityNATDest | ||
case firewallapi.ChainPriorityFilter: | ||
chain.Priority = nftables.ChainPriorityFilter | ||
case firewallapi.ChainPrioritySecurity: | ||
chain.Priority = nftables.ChainPrioritySecurity | ||
case firewallapi.ChainPriorityNATSource: | ||
chain.Priority = nftables.ChainPriorityNATSource | ||
case firewallapi.ChainPrioritySELinuxLast: | ||
chain.Priority = nftables.ChainPrioritySELinuxLast | ||
case firewallapi.ChainPriorityConntrackHelper: | ||
chain.Priority = nftables.ChainPriorityConntrackHelper | ||
case firewallapi.ChainPriorityConntrackConfirm: | ||
chain.Priority = nftables.ChainPriorityConntrackConfirm | ||
case firewallapi.ChainPriorityLast: | ||
chain.Priority = nftables.ChainPriorityLast | ||
} | ||
} | ||
|
||
func setType(chain *nftables.Chain, chainType firewallapi.ChainType) { | ||
switch chainType { | ||
case firewallapi.ChainTypeFilter: | ||
chain.Type = nftables.ChainTypeFilter | ||
case firewallapi.ChainTypeRoute: | ||
chain.Type = nftables.ChainTypeRoute | ||
case firewallapi.ChainTypeNAT: | ||
chain.Type = nftables.ChainTypeNAT | ||
} | ||
} | ||
|
||
func setPolicy(chain *nftables.Chain, policy firewallapi.ChainPolicy) { | ||
switch policy { | ||
case firewallapi.ChainPolicyDrop: | ||
p := nftables.ChainPolicyDrop | ||
chain.Policy = &p | ||
case firewallapi.ChainPolicyAccept: | ||
p := nftables.ChainPolicyAccept | ||
chain.Policy = &p | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2019-2023 The Liqo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package firewall contains the controller that manages the firewall configuration. | ||
package firewall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2019-2023 The Liqo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package firewall | ||
|
||
import ( | ||
"context" | ||
|
||
ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
|
||
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1" | ||
) | ||
|
||
const ( | ||
// firewallConfigurationsControllerFinalizer is the finalizer added to virtual-node to allow the controller to clean up. | ||
firewallConfigurationsControllerFinalizer = "firewallconfigurations-controller.liqo.io/finalizer" | ||
) | ||
|
||
func (r *FirewallConfigurationReconciler) ensureFirewallConfigurationFinalizerPresence( | ||
ctx context.Context, fwcfg *networkingv1alpha1.FirewallConfiguration) error { | ||
ctrlutil.AddFinalizer(fwcfg, firewallConfigurationsControllerFinalizer) | ||
return r.Client.Update(ctx, fwcfg) | ||
} | ||
|
||
func (r *FirewallConfigurationReconciler) ensureFirewallConfigurationFinalizerAbsence( | ||
ctx context.Context, fwcfg *networkingv1alpha1.FirewallConfiguration) error { | ||
ctrlutil.RemoveFinalizer(fwcfg, firewallConfigurationsControllerFinalizer) | ||
return r.Client.Update(ctx, fwcfg) | ||
} |
Oops, something went wrong.