Skip to content

Commit

Permalink
cmd: Display decryption interfaces in encrypt status
Browse files Browse the repository at this point in the history
This commit adds a new line to cilium encrypt status, with the
list of interfaces on which decryption can happen:

    $ ks exec ds/cilium -c cilium-agent -- cilium encrypt status
    Encryption: IPsec
    Decryption interface(s): eth0, eth1, eth2
    Keys in use: 1
    Max Seq. Number: 0x6e/0xffffffff
    Errors: 0

This can be useful to check that Cilium is attached to all the
interfaces it should be attached to (all those that can receive remote
pod traffic).

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
  • Loading branch information
pchaigno committed Oct 17, 2023
1 parent 24993fe commit d5b3db5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Documentation/security/network/encryption-ipsec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,17 @@ Troubleshooting
$ cilium-dbg encrypt status
Encryption: IPsec
Decryption interface(s): eth0, eth1, eth2
Keys in use: 1
Max Seq. Number: 0x1e3/0xffffffff
Errors: 0
If the error counter is non-zero, additional information will be displayed
with the specific errors the kernel encountered. If the sequence number
reaches its maximum value, it will also result in errors. The number of
keys in use should be 2 during a key rotation and always 1 otherwise.
keys in use should be 2 during a key rotation and always 1 otherwise. The
list of decryption interfaces should have all native devices that may
receive pod traffic (ex. ENI interfaces).

* All XFRM errors correspond to a packet drop in the kernel. Except for
``XfrmFwdHdrError`` and ``XfrmInError``, all XFRM errors indicate a bug in
Expand Down
35 changes: 35 additions & 0 deletions cilium-dbg/cmd/encrypt_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,44 @@ func getEncryptionMode() {
}
}

func isDecryptionInterface(link netlink.Link) (bool, error) {
filters, err := netlink.FilterList(link, tcFilterParentIngress)
if err != nil {
return false, err
}
for _, f := range filters {
if bpfFilter, ok := f.(*netlink.BpfFilter); ok {
if strings.Contains(bpfFilter.Name, "cil_from_network") {
return true, nil
}
}
}
return false, nil
}

func getDecryptionInterfaces() []string {
decryptionIfaces := []string{}
links, err := netlink.LinkList()
if err != nil {
Fatalf("Failed to list interfaces: %s", err)
}
for _, link := range links {
itIs, err := isDecryptionInterface(link)
if err != nil {
Fatalf("Failed to list BPF programs for %s: %s", link.Attrs().Name, err)
}
if itIs {
decryptionIfaces = append(decryptionIfaces, link.Attrs().Name)
}
}
return decryptionIfaces
}

func dumpIPsecStatus() {
keys := countUniqueIPsecKeys()
oseq := maxSequenceNumber()
interfaces := getDecryptionInterfaces()
fmt.Printf("Decryption interface(s): %s\n", strings.Join(interfaces, ", "))
fmt.Printf("Keys in use: %-26d\n", keys)
fmt.Printf("Max Seq. Number: %s\n", oseq)
errCount, errMap := getXfrmStats("")
Expand Down

0 comments on commit d5b3db5

Please sign in to comment.