# Filtering UDP traffic using p4rtshell

**URL:** <https://forum.p4.org/t/filtering-udp-traffic-using-p4rtshell/716>\
**Category:** Getting Started with P4\
**Created:** [March 30, 2023, 2:43pm UTC](https://forum.p4.org/t/filtering-udp-traffic-using-p4rtshell/716 "2023-03-30T14:43:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JanRepka](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@JanRepka](https://forum.p4.org/u/JanRepka)\
**Post date:** [March 30, 2023, 2:43pm UTC](https://forum.p4.org/t/filtering-udp-traffic-using-p4rtshell/716/1 "2023-03-30T14:43:28Z")

</div>

Hello,

I’m trying to use [traffic filter](https://github.com/p4lang/p4pi/wiki/Example-%234---Traffic-filter) example on P4Pi with t4p4s target to filter UDP packets by their source port. When I filter by IPv4 source address the packets drop correctly. To add filters I’m using p4rtshell as control plane with the following commands:

```auto
te = table_entry["MyIngress.udp_srcPort_filter"](action="MyIngress.drop")
te.match["hdr.udp.srcPort"] = <source_port>
te.insert()

```

This doesn’t filter traffic at all. I tested packets with empty payload and tried to filter on UDP length which also didn’t work. When I checked `hdr.udp.isValid()` it seems to return `true` which confuses me even more.

Can you help me resolve this issue?

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [March 30, 2023, 4:55pm UTC](https://forum.p4.org/t/filtering-udp-traffic-using-p4rtshell/716/2 "2023-03-30T16:55:53Z")

</div>

I do not know if the t4p4s target has detailed logging capabilities that can be enabled that are in any way similar to the ones in the BMv2 simple\_switch\_grpc process, but if it does, I would recommend enabling those and seeing what it says happens while a sample UDP packet that you think should match is processed.

Also, if you could publish complete P4 source code and any relevant controller programs of an example that successfully filters by IPv4 source address where the packets drop as you expect, vs. the smallest changes you can make that tries to filter instead by UDP source port but does not drop packets as as you expect, that may help others diagnose the issue.

---

<div class="post-metadata">

**Author:** ![JanRepka](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@JanRepka](https://forum.p4.org/u/JanRepka)\
**Post date:** [April 13, 2023, 1:22pm UTC](https://forum.p4.org/t/filtering-udp-traffic-using-p4rtshell/716/3 "2023-04-13T13:22:29Z")

</div>

The filter was using an `ipv4.src.hit() OR ipv4.dst.hit()` but for udp there was an AND statement, and I just missed it. That was what was causing my issue.
