<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NetworkPolicy Archives - Linuxcent</title>
	<atom:link href="https://linuxcent.com/tag/networkpolicy/feed/" rel="self" type="application/rss+xml" />
	<link>https://linuxcent.com/tag/networkpolicy/</link>
	<description>Infrastructure security, from the kernel up.</description>
	<lastBuildDate>Mon, 06 Jul 2026 03:36:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>

<image>
	<url>https://linuxcent.com/wp-content/uploads/2026/04/favicon-512x512-1-150x150.png</url>
	<title>NetworkPolicy Archives - Linuxcent</title>
	<link>https://linuxcent.com/tag/networkpolicy/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">211632295</site>	<item>
		<title>TC eBPF — Pod-Level Network Policy Without iptables</title>
		<link>https://linuxcent.com/tc-ebpf-kubernetes-network-policy/</link>
					<comments>https://linuxcent.com/tc-ebpf-kubernetes-network-policy/#respond</comments>
		
		<dc:creator><![CDATA[Vamshi Krishna Santhapuri]]></dc:creator>
		<pubDate>Sun, 03 May 2026 02:00:00 +0000</pubDate>
				<category><![CDATA[eBPF]]></category>
		<category><![CDATA[Cilium]]></category>
		<category><![CDATA[Kubernetes]]></category>
		<category><![CDATA[Linux Networking]]></category>
		<category><![CDATA[NetworkPolicy]]></category>
		<category><![CDATA[SRE]]></category>
		<category><![CDATA[TC eBPF]]></category>
		<guid isPermaLink="false">https://linuxcent.com/?p=1837</guid>

					<description><![CDATA[<p><span class="span-reading-time rt-reading-time" style="display: block;"><span class="rt-label rt-prefix">Reading Time: </span> <span class="rt-time"> 10</span> <span class="rt-label rt-postfix">minutes</span></span>TC eBPF Kubernetes network policy relies on pod identity Cilium attaches at the veth. Why XDP alone isn't enough, and how to debug stale TC filters.</p>
<p>The post <a href="https://linuxcent.com/tc-ebpf-kubernetes-network-policy/">TC eBPF — Pod-Level Network Policy Without iptables</a> appeared first on <a href="https://linuxcent.com">Linuxcent</a>.</p>
]]></description>
										<content:encoded><![CDATA[<span class="span-reading-time rt-reading-time" style="display: block;"><span class="rt-label rt-prefix">Reading Time: </span> <span class="rt-time"> 10</span> <span class="rt-label rt-postfix">minutes</span></span><style>
pre{position:relative;background:#1e1e1e;color:#d4d4d4;
    padding:16px 16px 16px 20px;border-radius:6px;overflow-x:auto;
    font-family:'JetBrains Mono','Fira Code','Cascadia Code',Consolas,'Courier New',monospace;
    font-size:.88em;line-height:1.6;border-left:4px solid #555}
code{background:#f4f4f4;padding:2px 5px;border-radius:3px;font-size:.9em}
pre code{background:transparent;padding:0;color:inherit}
pre[data-lang="bash"],pre[data-lang="sh"],
pre[data-lang="shell"],pre[data-lang="zsh"]{border-left-color:#4ec9b0}
pre[data-lang="yaml"],pre[data-lang="json"],
pre[data-lang="toml"],pre[data-lang="xml"]{border-left-color:#569cd6}
pre[data-lang="python"],pre[data-lang="go"],pre[data-lang="rust"],
pre[data-lang="java"],pre[data-lang="c"],pre[data-lang="cpp"]{border-left-color:#c586c0}
pre[data-lang="text"],pre[data-lang="output"],
pre[data-lang="console"]{border-left-color:#888}
.lc-copy-btn{position:absolute;top:8px;right:8px;background:#2d2d2d;color:#ccc;
    border:1px solid #444;border-radius:4px;padding:3px 9px;font-size:.75em;
    font-family:system-ui,sans-serif;cursor:pointer;opacity:0;
    transition:opacity .15s,background .15s;line-height:1.6}
pre:hover .lc-copy-btn{opacity:1}
.lc-copy-btn:hover{background:#3a3a3a;color:#fff}
.lc-copy-btn.copied{color:#4ec9b0;border-color:#4ec9b0}
.lc-lang-badge{position:absolute;top:8px;left:20px;font-family:system-ui,sans-serif;
    font-size:.7em;color:#666;text-transform:uppercase;letter-spacing:.04em;
    line-height:1;pointer-events:none;opacity:0;transition:opacity .15s}
pre:hover .lc-lang-badge{opacity:1}
table{border-collapse:collapse;width:100%;margin:16px 0}
th,td{border:1px solid #ddd;padding:10px 14px;text-align:left}
th{background:#f0f0f0;font-weight:600}
tr:nth-child(even){background:#fafafa}
</style>
<p><script>
(function(){
  if(window.__lcCodeEnhanced)return;
  window.__lcCodeEnhanced=true;
  function enhance(){
    document.querySelectorAll('pre').forEach(function(pre){
      var code=pre.querySelector('code');
      var lang='';
      if(code){var m=(code.className||'').match(/language-(\S+)/);if(m)lang=m[1].toLowerCase();}
      if(lang)pre.setAttribute('data-lang',lang);
      if(lang){var badge=document.createElement('span');badge.className='lc-lang-badge';badge.textContent=lang;pre.insertBefore(badge,pre.firstChild);}
      var btn=document.createElement('button');
      btn.className='lc-copy-btn';btn.textContent='Copy';btn.setAttribute('aria-label','Copy code to clipboard');
      pre.appendChild(btn);
      btn.addEventListener('click',function(){
        var text=code?code.innerText:pre.innerText;
        if(navigator.clipboard&&window.isSecureContext){
          navigator.clipboard.writeText(text).then(function(){ok(btn);}).catch(function(){fb(text,btn);});
        }else{fb(text,btn);}
      });
    });
  }
  function ok(btn){btn.textContent='Copied!';btn.classList.add('copied');setTimeout(function(){btn.textContent='Copy';btn.classList.remove('copied');},2000);}
  function fb(text,btn){
    try{var ta=document.createElement('textarea');ta.value=text;ta.style.cssText='position:fixed;left:-9999px;top:-9999px;opacity:0';document.body.appendChild(ta);ta.select();document.execCommand('copy');document.body.removeChild(ta);ok(btn);}
    catch(e){btn.textContent='✗ Failed';setTimeout(function(){btn.textContent='Copy';},2000);}
  }
  if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',enhance);}else{enhance();}
})();
</script></p>
<p><em>eBPF: From Kernel to Cloud, Episode 8</em><br />
<em><a href="https://linuxcent.com/what-is-ebpf-linux-kubernetes/">What Is eBPF?</a> · <a href="https://linuxcent.com/bpf-verifier-kubernetes-safety/">The BPF Verifier</a> · <a href="https://linuxcent.com/ebpf-vs-kernel-modules-kubernetes/">eBPF vs Kernel Modules</a> · <a href="https://linuxcent.com/ebpf-program-types-kubernetes/">eBPF Program Types</a> · <a href="https://linuxcent.com/ebpf-maps-explained/">eBPF Maps</a> · <a href="https://linuxcent.com/ebpf-co-re-libbpf-portable-programs/">CO-RE and libbpf</a> · <a href="https://linuxcent.com/ebpf-xdp-kubernetes-networking/">XDP</a> · </em><em>TC eBPF</em>**</p>
<hr />
<h2 id="tldr">TL;DR</h2>
<ul>
<li>TC eBPF fires after <code class="" data-line="">sk_buff</code> allocation — it has socket metadata, cgroup ID, and pod identity that XDP lacks<br />
<em>(<code class="" data-line="">sk_buff</code> = the kernel&#8217;s socket buffer, allocated for every packet; TC fires after this allocation, so it can read socket and process identity)</em></li>
<li>Direct action (DA) mode combines filter and action; the program&#8217;s return value is the packet fate</li>
<li>Multiple TC programs chain on the same hook ordered by priority — stale programs from Cilium upgrades cause silent policy conflicts</li>
<li><code class="" data-line="">tc filter show dev &lt;iface&gt; ingress/egress</code> is the primary inspection tool; <code class="" data-line="">bpftool net list</code> shows the full node picture</li>
<li>XDP + TC is the Cilium data path: XDP for pre-stack service load balancing, TC for per-pod identity-based enforcement</li>
<li>TC can modify packet content (<code class="" data-line="">bpf_skb_store_bytes</code>) — the basis for TC-based DNAT and packet mangling</li>
</ul>
<hr />
<p>TC eBPF is where Cilium implements pod-level network policy without iptables — the hook that fires after <code class="" data-line="">sk_buff</code> allocation, where socket and cgroup context exist, making per-pod enforcement possible. The obvious follow-up to XDP is why Cilium doesn&#8217;t use it for everything — pod network policy, egress enforcement, the full NetworkPolicy ruleset. The answer reveals an inherent trade-off built into the Linux data path: XDP&#8217;s speed comes from running before any context exists. At the moment it fires, there is no socket, no cgroup, no way to tell which pod sent the packet. The moment you need pod identity, you need a hook that fires later — and pays for it.</p>
<hr />
<p>A specific pod in production was experiencing intermittent TCP connection failures to an external service. Not all connections — roughly one in fifty. Kubernetes NetworkPolicy showed egress allowed for the namespace. Cilium policy status showed no violations. Running <code class="" data-line="">curl</code> from inside the pod worked fine.</p>
<p>The application logs told a different story: connection timeouts at the 30-second mark, no SYN-ACK received. Not a DNS issue — I verified with <code class="" data-line="">tcpdump</code> inside the pod namespace. SYN packets were leaving the pod network namespace. They weren&#8217;t making it onto the wire.</p>
<p>I ran <code class="" data-line="">bpftool net list</code> on the node and saw two TC egress programs attached to that pod&#8217;s veth interface. One from the current Cilium version (installed six weeks ago). One from the previous version — from before the rolling upgrade. Two programs. Different policy epochs. The older one had a stale block rule that fired intermittently based on connection tuple patterns it was never designed to handle in the new policy model.</p>
<p>Without understanding TC eBPF — what programs attach where, how multiple programs interact, and how to inspect them — I would have kept chasing ghosts in the application layer.</p>
<h2 id="quick-check-are-there-stale-tc-filters-on-your-cluster">Quick Check: Are There Stale TC Filters on Your Cluster?</h2>
<p>The most common TC eBPF issue on production clusters — stale filters left behind by a Cilium upgrade — is a two-command check:</p>
<pre><code class="" data-line=""># SSH into a worker node, then pick any pod&#039;s veth interface:
ip link | grep lxc | head -5
# lxc8a3f21b@if7: ...
# lxc2c9d3e1@if9: ...

# Check TC filters on that interface
tc filter show dev lxc8a3f21b egress
</code></pre>
<p><strong>Healthy output (one filter, one priority):</strong></p>
<pre><code class="" data-line="">filter protocol all pref 1 bpf chain 0
filter protocol all pref 1 bpf chain 0 handle 0x1 cil_to_container direct-action not_in_hw id 44
</code></pre>
<p><strong>Stale filter present (two priorities = problem):</strong></p>
<pre><code class="" data-line="">filter protocol all pref 1 bpf chain 0
filter protocol all pref 1 bpf chain 0 handle 0x1 cil_to_container direct-action not_in_hw id 44
filter protocol all pref 2 bpf chain 0
filter protocol all pref 2 bpf chain 0 handle 0x1 old_cil_to_container direct-action not_in_hw id 17
#                  ^^^^^^ two different priorities = two programs running in sequence
</code></pre>
<p>Two priorities on the same hook means two programs running sequentially. If the older one has a stale DROP rule, packets are being dropped intermittently — and nothing in the application layer will tell you why.</p>
<blockquote>
<p><strong>Not running Cilium?</strong> If you&#8217;re on a non-Cilium CNI (Calico, Flannel, <code class="" data-line="">aws-vpc-cni</code>), you likely won&#8217;t have TC eBPF filters on pod interfaces. Run <code class="" data-line="">tc filter show dev eth0 ingress</code> on the node uplink instead to see if any TC programs are attached at the node level. An empty response is normal for non-Cilium clusters.</p>
</blockquote>
<h2 id="why-tc-not-xdp">Why TC, Not XDP</h2>
<p>EP07 covered XDP: fastest possible hook, fires before <code class="" data-line="">sk_buff</code>, drops at line rate. If XDP is so fast, why doesn&#8217;t Cilium use it for everything?</p>
<p>Because XDP sees only raw packet bytes. No socket. No cgroup. No pod identity.</p>
<p>In Kubernetes, network policy is inherently about identity. &#8220;Allow pod A to connect to pod B on port 8080.&#8221; To enforce this, you need to know which pod a packet is coming from on egress — and which pod it&#8217;s going to on ingress. That mapping lives in the cgroup hierarchy and the socket buffer, neither of which exist at XDP time.</p>
<p>TC fires later in the packet lifecycle, after <code class="" data-line="">sk_buff</code> is allocated and populated:</p>
<pre><code class="" data-line="">Ingress path:
  wire → NIC → [XDP hook] → sk_buff allocated → [TC ingress hook] → netfilter → socket

Egress path:
  socket → IP routing → [TC egress hook] → qdisc → NIC → wire
</code></pre>
<p>At the TC egress hook on a pod&#8217;s veth interface, the <code class="" data-line="">sk_buff</code> carries the socket that created the packet — and from that socket you can read the cgroup ID. The cgroup hierarchy maps container → pod, so the TC program knows which pod this traffic belongs to. That&#8217;s what makes pod-level enforcement possible.</p>
<h2 id="the-linux-traffic-control-architecture">The Linux Traffic Control Architecture</h2>
<p><code class="" data-line="">tc</code> (traffic control) is the Linux subsystem for managing packet queues and scheduling. Most Linux administrators know it as the bandwidth-shaping tool:</p>
<pre><code class="" data-line=""># Classic tc usage — rate limit an interface
tc qdisc add dev eth0 root tbf rate 100mbit burst 32kbit latency 400ms
</code></pre>
<p>The qdisc (queuing discipline) is the primary abstraction. Under the qdisc sits a <strong>filter</strong> layer — and the filter type relevant to eBPF is <code class="" data-line="">cls_bpf</code>, which attaches eBPF programs as packet classifiers.</p>
<blockquote>
<p><strong>qdisc (queuing discipline)</strong> is the kernel&#8217;s packet scheduler for an interface — it controls how packets are buffered and in what order they leave. For eBPF policy enforcement, Cilium uses a special qdisc called <code class="" data-line="">clsact</code> which has no buffering behaviour at all; it purely provides the ingress and egress hook points where eBPF filters attach. If a pod veth doesn&#8217;t have <code class="" data-line="">clsact</code>, Cilium isn&#8217;t enforcing policy on that pod.</p>
</blockquote>
<p>Cilium attaches <code class="" data-line="">cls_bpf</code> filters in <strong>direct action</strong> (DA) mode, which combines classifier and action into a single eBPF program. The program&#8217;s return value is the packet fate directly:</p>
<table>
<thead>
<tr>
<th>Return value</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="" data-line="">TC_ACT_OK</code> (0)</td>
<td>Pass the packet</td>
</tr>
<tr>
<td><code class="" data-line="">TC_ACT_SHOT</code> (2)</td>
<td>Drop the packet</td>
</tr>
<tr>
<td><code class="" data-line="">TC_ACT_REDIRECT</code> (7)</td>
<td>Redirect to another interface</td>
</tr>
<tr>
<td><code class="" data-line="">TC_ACT_PIPE</code> (3)</td>
<td>Pass to the next filter in the chain</td>
</tr>
</tbody>
</table>
<h2 id="tc-context-what-your-program-can-see">TC Context: What Your Program Can See</h2>
<p>TC programs receive a <code class="" data-line="">struct __sk_buff</code> — a safe, BPF-accessible projection of the kernel <code class="" data-line="">sk_buff</code>. Unlike the raw packet bytes in XDP, <code class="" data-line="">__sk_buff</code> includes metadata:</p>
<pre><code class="" data-line="">struct __sk_buff {
    __u32 len;           // packet length
    __u32 pkt_type;      // PACKET_HOST, PACKET_BROADCAST, etc.
    __u32 mark;          // skb-&gt;mark — used by Cilium for pod identity
    __u32 queue_mapping;
    __u32 protocol;      // ETH_P_IP, ETH_P_IPV6, etc.
    __u32 vlan_present;
    __u32 vlan_tci;
    __u32 vlan_proto;
    __u32 priority;
    __u32 ingress_ifindex;
    __u32 ifindex;
    __u32 tc_index;
    __u32 cb[5];
    __u32 hash;
    __u32 tc_classid;
    __u32 data;          // offset to packet data
    __u32 data_end;
    __u32 napi_id;
    __u32 family;
    __u32 remote_ip4;    // source IP (ingress) or dest IP (egress)
    __u32 local_ip4;
    __u32 remote_port;
    __u32 local_port;
    // ...
};
</code></pre>
<p><code class="" data-line="">skb-&gt;mark</code> is how Cilium passes pod identity between its hook points.</p>
<blockquote>
<p><strong><code class="" data-line="">skb-&gt;mark</code></strong> is a 32-bit field in every <code class="" data-line="">sk_buff</code> that any kernel subsystem can read or write. It&#8217;s a general-purpose scratch field — iptables uses it, routing rules use it, and Cilium uses it to carry pod security identity from the socket hook through to TC enforcement. When Cilium stamps a pod&#8217;s identity into <code class="" data-line="">skb-&gt;mark</code> at connection time, every subsequent TC filter on that packet&#8217;s path can read it without another identity lookup. The socket-level cgroup hook (<code class="" data-line="">cgroup_sock_addr</code>) stamps the cgroup-derived pod identity into <code class="" data-line="">skb-&gt;mark</code> when the socket calls <code class="" data-line="">connect()</code>. By the time the packet reaches the TC egress hook, <code class="" data-line="">skb-&gt;mark</code> carries the pod&#8217;s security identity — and the TC program uses it for policy enforcement.</p>
</blockquote>
<h2 id="what-ciliums-tc-filters-actually-do">What Cilium&#8217;s TC Filters Actually Do</h2>
<p>The TC filter on each pod&#8217;s veth is Cilium&#8217;s enforcement point for Kubernetes NetworkPolicy. The mechanism:</p>
<ol>
<li>When a pod opens a connection, a <code class="" data-line="">cgroup_sock_addr</code> hook stamps the pod&#8217;s security identity (derived from its labels + namespace) into <code class="" data-line="">skb-&gt;mark</code></li>
<li>The TC egress filter on the veth reads <code class="" data-line="">skb-&gt;mark</code>, looks up the pod identity + destination in the policy map, and returns <code class="" data-line="">TC_ACT_SHOT</code> (drop) or <code class="" data-line="">TC_ACT_OK</code> (pass)</li>
<li>The TC ingress filter on the receiving pod&#8217;s veth does the same check for inbound traffic</li>
</ol>
<p>The policy map is a BPF LRU hash keyed on <code class="" data-line="">{pod_identity, dst_ip, dst_port, protocol}</code>. This is what <code class="" data-line="">cilium policy get</code> reads from — and what <code class="" data-line="">bpftool map dump</code> shows directly:</p>
<pre><code class="" data-line=""># Find Cilium&#039;s policy maps
bpftool map list | grep -i policy

# Dump the active policy entries for a specific endpoint
# Get endpoint ID from: cilium endpoint list
cilium bpf policy get &lt;endpoint-id&gt;

# Cross-check with raw bpftool dump
bpftool map dump id &lt;POLICY_MAP_ID&gt; | head -30
</code></pre>
<p>The <code class="" data-line="">clsact</code> qdisc is the prerequisite for any TC eBPF filter — it creates the ingress and egress hook points without any queuing behavior. Every pod veth on a Cilium node has one:</p>
<pre><code class="" data-line="">tc qdisc show dev lxcABCDEF
# qdisc clsact ffff: dev lxcABCDEF parent ffff:fff1
# ^^^^^^^^^^^^ this line confirms Cilium&#039;s hook points exist on this pod&#039;s veth
# If this is missing: Cilium is NOT enforcing NetworkPolicy on this pod
</code></pre>
<p>If a pod veth doesn&#8217;t show <code class="" data-line="">clsact</code>, Cilium isn&#8217;t enforcing policy on that pod.</p>
<h2 id="multiple-programs-and-the-filter-chain">Multiple Programs and the Filter Chain</h2>
<p>This is the detail that caused my production incident.</p>
<p>TC supports chaining multiple filters on the same hook, ordered by priority. Lower priority number runs first. When Cilium upgrades, it installs a new filter at a new priority before removing the old one. If the upgrade procedure has any timing gap — or if the removal step fails silently — you end up with two programs running in sequence.</p>
<pre><code class="" data-line=""># Show all TC filters on a pod&#039;s veth — both priorities visible
tc filter show dev lxc12345 egress

# Example output with a stale filter:
filter protocol all pref 1 bpf chain 0
filter protocol all pref 1 bpf chain 0 handle 0x1 cil_to_container direct-action not_in_hw id 44
filter protocol all pref 2 bpf chain 0
filter protocol all pref 2 bpf chain 0 handle 0x1 old_cil_to_container direct-action not_in_hw id 17
</code></pre>
<p>Two programs. Pref 1 runs first. Pref 2 runs second — unless pref 1 returned <code class="" data-line="">TC_ACT_SHOT</code>, in which case the packet is already dropped and pref 2 never fires.</p>
<p>In my incident: pref 1 was the current Cilium version with correct policy, returning <code class="" data-line="">TC_ACT_OK</code> for the traffic in question. Pref 2 was the old version with a stale block entry, returning <code class="" data-line="">TC_ACT_SHOT</code> for a subset of connection tuples. Because <code class="" data-line="">TC_ACT_OK</code> passes to the next filter in the chain (<code class="" data-line="">TC_ACT_PIPE</code> would do the same), pref 2 got to run — and intermittently dropped packets.</p>
<p>The fix:</p>
<pre><code class="" data-line=""># Remove the stale filter by priority
tc filter del dev lxc12345 egress pref 2

# Verify only the current filter remains
tc filter show dev lxc12345 egress
</code></pre>
<p>This should be part of any post-upgrade verification for Cilium-managed clusters.</p>
<h2 id="how-cilium-uses-tc-across-the-full-node">How Cilium Uses TC Across the Full Node</h2>
<p>Cilium&#8217;s TC deployment on a node:</p>
<pre><code class="" data-line="">Pod veth (host-side, lxcXXXXX):
  TC ingress: cil_from_container — L3/L4 policy on the pod&#039;s outbound traffic
  TC egress:  cil_to_container   — L3/L4 policy on traffic arriving at the pod

Node uplink (eth0):
  TC ingress: cil_from_netdev    — traffic arriving from outside the node
  TC egress:  cil_to_netdev      — traffic leaving the node

XDP on eth0:
  cil_xdp_entry — pre-stack service load balancing (DNAT for ClusterIP)
</code></pre>
<p>The naming is counterintuitive at first: <code class="" data-line="">cil_from_container</code> is attached to the TC <strong>ingress</strong> hook on the veth.</p>
<blockquote>
<p><strong>Veth direction confusion:</strong> TC ingress/egress is named from the kernel&#8217;s perspective of the interface, not the pod&#8217;s. The host-side veth interface <em>receives</em> traffic that the pod is <em>sending</em> — so TC ingress on the host veth = the pod&#8217;s outbound traffic. This trips up everyone the first time. When debugging, always confirm direction with <code class="" data-line="">tc filter show dev lxcXXX ingress</code> and <code class="" data-line="">egress</code> separately, and check which Cilium program name is attached (<code class="" data-line="">cil_from_container</code> = pod outbound, <code class="" data-line="">cil_to_container</code> = pod inbound). The veth ingress direction from the host perspective is traffic flowing out of the container. Traffic leaving the pod hits the host-side veth ingress, which is <code class="" data-line="">cil_from_container</code>. It enforces egress policy for the pod. Naming follows the kernel&#8217;s perspective of the interface, not the application&#8217;s.</p>
</blockquote>
<p>To see the full picture on a node:</p>
<pre><code class="" data-line=""># All eBPF network programs (XDP and TC) across all interfaces
bpftool net list

# TC-specific view
for iface in $(ip link | grep lxc | awk -F&#039;: &#039; &#039;{print $2}&#039;); do
    echo &quot;=== $iface ===&quot;
    tc filter show dev $iface ingress
    tc filter show dev $iface egress
done
</code></pre>
<h2 id="tc-can-modify-packets-too">TC Can Modify Packets Too</h2>
<p>Unlike XDP, TC programs have full access to the <code class="" data-line="">sk_buff</code> and can modify packet content — headers, payload, and checksums. This is how TC-based DNAT works in Cilium when XDP isn&#8217;t available on the NIC: the program rewrites the destination IP at L3 and updates the IP + transport checksums atomically. The kernel BPF helper handles the checksum recalculation.</p>
<p>From an operational standpoint: if you see a TC program attached but expected traffic is being redirected rather than dropped, the program is likely doing DNAT. <code class="" data-line="">bpftool prog dump xlated id &lt;ID&gt;</code> shows the disassembled instructions and will reveal <code class="" data-line="">bpf_skb_store_bytes</code> calls if packet rewriting is happening.</p>
<h2 id="debugging-tc-programs-in-production">Debugging TC Programs in Production</h2>
<p>Workflow I follow when investigating network issues on Cilium clusters:</p>
<pre><code class="" data-line=""># 1. List all eBPF network programs (see the full picture)
bpftool net list

# 2. Check specific interface for stale TC filters
tc filter show dev lxcABCDEF ingress
tc filter show dev lxcABCDEF egress

# 3. Inspect a specific program
bpftool prog show id 44

# 4. Disassemble a program (last resort for understanding behavior)
bpftool prog dump xlated id 44

# 5. Check Cilium&#039;s view of the same interface
cilium endpoint list
cilium endpoint get &lt;endpoint-id&gt;

# 6. Enable verbose TC program logs (debug builds only)
# Cilium: set CILIUM_DEBUG=true in the deployment
</code></pre>
<h2 id="common-mistakes">Common Mistakes</h2>
<table>
<thead>
<tr>
<th>Mistake</th>
<th>Impact</th>
<th>Fix</th>
</tr>
</thead>
<tbody>
<tr>
<td>Not checking for stale TC filters after Cilium upgrades</td>
<td>Conflicting policy programs cause intermittent drops</td>
<td>Run <code class="" data-line="">tc filter show</code> post-upgrade; remove stale by priority</td>
</tr>
<tr>
<td>Confusing ingress/egress direction on veth interfaces</td>
<td>Policy applied to wrong traffic direction</td>
<td>TC ingress on host-side veth = pod&#8217;s outbound traffic</td>
</tr>
<tr>
<td>Attaching TC without <code class="" data-line="">clsact</code> qdisc</td>
<td>Filter attachment fails</td>
<td><code class="" data-line="">tc qdisc add dev &lt;iface&gt; clsact</code> before filter add</td>
</tr>
<tr>
<td>Using <code class="" data-line="">TC_ACT_OK</code> when you want to stop the chain</td>
<td>Subsequent filters still run</td>
<td>Use <code class="" data-line="">TC_ACT_OK</code> knowing the chain continues; use <code class="" data-line="">TC_ACT_REDIRECT</code> or explicit <code class="" data-line="">TC_ACT_SHOT</code> only</td>
</tr>
<tr>
<td>Expecting TC performance equal to XDP</td>
<td>TC has sk_buff overhead — it&#8217;s slower</td>
<td>Right tool: XDP for pre-stack bulk drops, TC for identity-aware policy</td>
</tr>
<tr>
<td>Hardcoding <code class="" data-line="">skb-&gt;mark</code> interpretation</td>
<td>Different tools use mark differently</td>
<td>Document mark field usage clearly; coordinate between Cilium and custom programs</td>
</tr>
</tbody>
</table>
<h2 id="key-takeaways">Key Takeaways</h2>
<ul>
<li>TC eBPF fires after <code class="" data-line="">sk_buff</code> allocation — it has socket metadata, cgroup ID, and pod identity that XDP lacks</li>
<li>Direct action (DA) mode combines filter and action; the program&#8217;s return value is the packet fate</li>
<li>Multiple TC programs chain on the same hook ordered by priority — stale programs from Cilium upgrades cause silent policy conflicts</li>
<li><code class="" data-line="">tc filter show dev &lt;iface&gt; ingress/egress</code> is the primary inspection tool; <code class="" data-line="">bpftool net list</code> shows the full node picture</li>
<li>XDP + TC is the Cilium data path: XDP for pre-stack service load balancing, TC for per-pod identity-based enforcement</li>
<li>TC can modify packet content (<code class="" data-line="">bpf_skb_store_bytes</code>) — the basis for TC-based DNAT and packet mangling</li>
</ul>
<h2 id="whats-next">What&#8217;s Next</h2>
<p>EP08 closes out the kernel machinery arc: program types, maps, CO-RE, XDP, TC. Five episodes on the engine under the tools. EP09 shifts from understanding the machinery to using it interactively.</p>
<p>bpftrace turns kernel knowledge into one-liners you can run on a live production node. Which process is touching this file right now? Where is this latency spike originating in the kernel call stack? Which container is making DNS queries to an unexpected resolver? Under 10 seconds per question — no restart, no sidecar, no instrumentation change.</p>
<p>Every bpftrace one-liner is a complete eBPF program compiled, loaded, run, and cleaned up on the fly. EP09 covers how that works and why it changes the way you investigate production incidents.</p>
<p><em>Next: <a href="/bpftrace-kernel-observability/">bpftrace — kernel answers in one line</a></em></p>
<p>Get EP09 in your inbox when it publishes → <a href="https://linuxcent.com/subscribe">linuxcent.com/subscribe</a></p>
<p><a class="a2a_button_mastodon" href="https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Flinuxcent.com%2Ftc-ebpf-kubernetes-network-policy%2F&amp;linkname=TC%20eBPF%20%E2%80%94%20Pod-Level%20Network%20Policy%20Without%20iptables" title="Mastodon" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_email" href="https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Flinuxcent.com%2Ftc-ebpf-kubernetes-network-policy%2F&amp;linkname=TC%20eBPF%20%E2%80%94%20Pod-Level%20Network%20Policy%20Without%20iptables" title="Email" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Flinuxcent.com%2Ftc-ebpf-kubernetes-network-policy%2F&amp;linkname=TC%20eBPF%20%E2%80%94%20Pod-Level%20Network%20Policy%20Without%20iptables" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Flinuxcent.com%2Ftc-ebpf-kubernetes-network-policy%2F&amp;linkname=TC%20eBPF%20%E2%80%94%20Pod-Level%20Network%20Policy%20Without%20iptables" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_x" href="https://www.addtoany.com/add_to/x?linkurl=https%3A%2F%2Flinuxcent.com%2Ftc-ebpf-kubernetes-network-policy%2F&amp;linkname=TC%20eBPF%20%E2%80%94%20Pod-Level%20Network%20Policy%20Without%20iptables" title="X" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Flinuxcent.com%2Ftc-ebpf-kubernetes-network-policy%2F&amp;linkname=TC%20eBPF%20%E2%80%94%20Pod-Level%20Network%20Policy%20Without%20iptables" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_copy_link" href="https://www.addtoany.com/add_to/copy_link?linkurl=https%3A%2F%2Flinuxcent.com%2Ftc-ebpf-kubernetes-network-policy%2F&amp;linkname=TC%20eBPF%20%E2%80%94%20Pod-Level%20Network%20Policy%20Without%20iptables" title="Copy Link" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Flinuxcent.com%2Ftc-ebpf-kubernetes-network-policy%2F&#038;title=TC%20eBPF%20%E2%80%94%20Pod-Level%20Network%20Policy%20Without%20iptables" data-a2a-url="https://linuxcent.com/tc-ebpf-kubernetes-network-policy/" data-a2a-title="TC eBPF — Pod-Level Network Policy Without iptables"></a></p><p>The post <a href="https://linuxcent.com/tc-ebpf-kubernetes-network-policy/">TC eBPF — Pod-Level Network Policy Without iptables</a> appeared first on <a href="https://linuxcent.com">Linuxcent</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://linuxcent.com/tc-ebpf-kubernetes-network-policy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1837</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: linuxcent.com @ 2026-08-28 17:34:17 by W3 Total Cache
-->