• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hknutzen / Netspoc-Approve / 16674559403

01 Aug 2025 12:03PM UTC coverage: 98.531% (-0.07%) from 98.6%
16674559403

push

github

hknutzen
CHANGELOG file

5230 of 5308 relevant lines covered (98.53%)

1.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/go/pkg/linux/config.go
1
package linux
2

3
import (
4
        "slices"
5

6
        "github.com/hknutzen/Netspoc-Approve/go/pkg/errlog"
7
)
8

9
func (s *State) LoadNetspoc(data []byte, fName string) error {
1✔
10
        cfg, err := s.ParseConfig(data, fName)
1✔
11
        if err != nil {
1✔
12
                return err
×
13
        }
×
14
        if s.spocCfg == nil {
2✔
15
                s.spocCfg = cfg
1✔
16
        } else {
2✔
17
                s.mergeSpoc(cfg)
1✔
18
        }
1✔
19
        return nil
1✔
20
}
21

22
func (s *State) MoveNetspoc2DeviceConfig() {
1✔
23
        s.deviceCfg, s.spocCfg = s.spocCfg, nil
1✔
24
}
1✔
25

26
func (s *State) mergeSpoc(b *config) {
1✔
27
        a := s.spocCfg
1✔
28
        a.routes = append(a.routes, b.routes...)
1✔
29
        for tName, bChains := range b.iptables {
2✔
30
                aChains := a.iptables[tName]
1✔
31
                if aChains == nil {
2✔
32
                        errlog.Info("Adding all chains of table %q", tName)
1✔
33
                        a.iptables[tName] = bChains
1✔
34
                        continue
1✔
35
                }
36
                for cName, bChain := range bChains {
2✔
37
                        aChain := aChains[cName]
1✔
38
                        if aChain == nil {
2✔
39
                                errlog.Info("Adding chain %q of table %q", cName, tName)
1✔
40
                                aChains[cName] = bChain
1✔
41
                                continue
1✔
42
                        }
43
                        switch aChain.policy {
1✔
44
                        case "-", "":
1✔
45
                                errlog.Abort("Must not redefine chain %q of table %q from rawdata",
1✔
46
                                        cName, tName)
1✔
47
                        }
48
                        for _, ru := range bChain.rules {
2✔
49
                                i := 0
1✔
50
                                if ru.append {
2✔
51
                                        // Append before last non DROP line.
1✔
52
                                        i = len(aChain.rules)
1✔
53
                                        for i > 0 {
2✔
54
                                                if aChain.rules[i-1].pairs["-j"] == "DROP" {
2✔
55
                                                        i--
1✔
56
                                                } else {
2✔
57
                                                        break
1✔
58
                                                }
59
                                        }
60
                                }
61
                                aChain.rules = slices.Insert(aChain.rules, i, ru)
1✔
62
                        }
63
                }
64
        }
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc