smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.79k stars 427 forks source link

How do I set SO_MARK? #598

Closed lazytiger closed 2 years ago

lazytiger commented 2 years ago

Is it possible to set SO_MARK in smoltcp?

Dirbaio commented 2 years ago

I assume you're asking about the RawSocket PHY? It's not directly supported, but you can get the FD with .as_raw_fd() and then dosetsockopt() on it yourself.

lazytiger commented 2 years ago

I want to set marks for all the packets coming from TapTunInterface, what should I do? Can I just setsockopt on TapTunInterface fd? Thanks

Dirbaio commented 2 years ago

I'm not sure it's possible with tun/tap. You can probably use iptables to mark all packets coming from tap0

lazytiger commented 2 years ago

I have tried the following iptables rules

iptables -t mangle -A OUTPUT -o tun0 -j MARK --set-mark 1

but no packets were matched

Dirbaio commented 2 years ago

Correct iptables usage is out of scope of smoltcp, I'm afraid.

lazytiger commented 2 years ago

Thanks for the reply.