Debian Codegraph @

pkg/ip/ipforward_linux.go

raw symbols SCIP
1 // Copyright 2015 CNI authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/
16
17 import (
18 "bytesscip-go gomod github.com/golang/go/src go1.24.2 bytes/"
19 "osscip-go gomod github.com/golang/go/src go1.24.2 os/"
20
21 currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/ "github.com/containernetworking/cni/pkg/types/100scip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/"
22 )
23
24 func EnableIP4Forwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/EnableIP4Forward().() error {
25 return echo1scip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/echo1().("/proc/sys/net/ipv4/ip_forward")
26 }
27
28 func EnableIP6Forwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/EnableIP6Forward().() error {
29 return echo1scip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/echo1().("/proc/sys/net/ipv6/conf/all/forwarding")
30 }
31
32 // EnableForward will enable forwarding for all configured
33 // address families
34 func EnableForwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/EnableForward().(ips []*currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.IPConfigscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#) error {
35 v4 := false
36 v6 := false
37
38 for _, ip := range ips {
39 isV4 := ip.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address..IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP..To4scip-go gomod github.com/golang/go/src go1.24.2 net/IP#To4().() != nil
40 if isV4 && !v4 {
41 if err := EnableIP4Forwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/EnableIP4Forward().(); err != nil {
42 return err
43 }
44 v4 = true
45 } else if !isV4 && !v6 {
46 if err := EnableIP6Forwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/EnableIP6Forward().(); err != nil {
47 return err
48 }
49 v6 = true
50 }
51 }
52 return nil
53 }
54
55 func echo1scip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/echo1().(f string) error {
56 if content, err := osscip-go gomod github.com/golang/go/src go1.24.2 os/.ReadFilescip-go gomod github.com/golang/go/src go1.24.2 os/ReadFile().(f); err == nil {
57 if bytesscip-go gomod github.com/golang/go/src go1.24.2 bytes/.Equalscip-go gomod github.com/golang/go/src go1.24.2 bytes/Equal().(bytesscip-go gomod github.com/golang/go/src go1.24.2 bytes/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.2 bytes/TrimSpace().(content), []byte("1")) {
58 return nil
59 }
60 }
61 return osscip-go gomod github.com/golang/go/src go1.24.2 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24.2 os/WriteFile().(f, []byte("1"), 0o644)
62 }