Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter: Add support for the csum action in u32 #718

Merged
merged 1 commit into from
Mar 29, 2022
Merged

Conversation

niax
Copy link
Contributor

@niax niax commented Dec 1, 2021

This patch adds support for the U32 action that can force a csum
recalculation in different layers of a packet. It closes #668

I wrote a small test program to match the behaviour of the equivalent tc invocation:

package main

import (
        "fmt"
        "github.com/vishvananda/netlink"
)

func main() {
        handle, err := netlink.NewHandle()
        if err != nil {
                panic(err)
        }

        link, err := handle.LinkByName("dummy0")
        if err != nil {
                panic(err)
        }

        // Key matches IPv6 packets
        u32_key_ipv6 :=
                netlink.TcU32Key{
                        Mask:    0x0000FF00,
                        Val:     0x00000600,
                        Off:     4,
                        OffMask: 0,
                }

        filter := netlink.U32{
                Actions: []netlink.Action{
                        &netlink.CsumAction{
                                ActionAttrs: netlink.ActionAttrs{
                                        Action: netlink.TC_ACT_UNSPEC,
                                },
                                UpdateFlags: netlink.TCA_CSUM_UPDATE_FLAG_TCP | netlink.TCA_CSUM_UPDATE_FLAG_UDP,
                        },
                },
                Sel: &netlink.TcU32Sel{
                        Keys: []netlink.TcU32Key{u32_key_ipv6},
                        Flags: netlink.TC_U32_TERMINAL,
                },
        }
        filter.LinkIndex = link.Attrs().Index
        filter.Parent = netlink.HANDLE_MIN_EGRESS
        filter.Priority = 999
        filter.Protocol = 3
        err = handle.FilterAdd(&filter)
        fmt.Printf("Errors: %+v\n", err)
}

This does the same as tc filter add dev dummy0 egress pref 200 u32 match ip6 protocol 6 0xff action csum tcp udp continue, which can be seen with a show:

$ tc filter show dev dummy0 egress
filter protocol all pref 200 u32 chain 0
filter protocol all pref 200 u32 chain 0 fh 800: ht divisor 1
filter protocol all pref 200 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 terminal flowid ??? not_in_hw
  match 00000600/0000ff00 at 4
        action order 1: csum (tcp, udp) action continue
        index 3 ref 1 bind 1

filter protocol all pref 999 u32 chain 0
filter protocol all pref 999 u32 chain 0 fh 801: ht divisor 1
filter protocol all pref 999 u32 chain 0 fh 801::800 order 2048 key ht 801 bkt 0 terminal flowid ??? not_in_hw
  match 00000600/0000ff00 at 4
        action order 1: csum (tcp, udp) action continue
        index 1 ref 1 bind 1

This patch adds support for the U32 action that can force a csum
recalculation in different layers of a packet.
@niax
Copy link
Contributor Author

niax commented Jan 4, 2022

@vishvananda (or someone else with perms to merge), is there something extra I'm missing to get this looked at?

@vishvananda vishvananda changed the base branch from master to main January 12, 2022 22:06
@vishvananda vishvananda reopened this Jan 12, 2022
@vishvananda
Copy link
Owner

This lgtm. I'll give @aboch a chance to comment on it before i merge

@niax
Copy link
Contributor Author

niax commented Mar 29, 2022

@aboch any comments on this, or can @vishvananda merge?

@aboch
Copy link
Collaborator

aboch commented Mar 29, 2022

LGTM

@aboch aboch merged commit 5cb84e4 into vishvananda:main Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for the Traffic Control csum action
3 participants