NIKSS-vSwitch / nikss

Native In-Kernel P4-programmable Software Switch for Software-Defined Networking (previously PSA-eBPF)
Apache License 2.0
48 stars 4 forks source link

add/get entry to LPM table without mask will only affect 0.0.0.0/0 entry #64

Closed stuart-chu closed 2 years ago

stuart-chu commented 2 years ago

In current version, manipulating entries in a LPM table with only IP will add mask /0 to the keys which eventually affect entry 0.0.0.0/0. This is caused by : parse_table_key will consider 192.168.2.12 as PSABPF_EXACT and fill_key_btf_info will add 192.168.2.12 to the IP part of LPM key_buffer and leave 0 to the mask part. In the end, the match key is 0.0.0.0/0.

example: after run cmd with

psabpf-ctl table add pipe 1 lpm action id 1 key 192.168.2.12 data 15

all get command without mask with return value of 0.0.0.0/0 and key with The Signs IP and type exact

psabpf-ctl table get pipe 1 lpm key 8.8.8.8

{
    "lpm": {
        "entries": [
            {
                "key": [
                    {
                        "type": "exact",
                        "value": "0x8080808"
                    }
                ],
                "action": {
                    "id": 1,
                    "name": "forward",
                    "parameters": [
                        {
                            "name": "dst_port",
                            "value": "0xf"
                        }
                    ]
                },
                "DirectCounter": {},
                "DirectMeter": {}
            }
        ],
        "DirectCounter": {}
    }

I think type exact should not be the key type of LPM table. If mask is not presented, it should run with mask 32 or throwing an error, rather than manipulating 0.0.0.0/0.

BRs, Stuart

osinstom commented 2 years ago

Thanks @stuart-chu for reporting this! We'll fix it soon and keep you updated.