last day (15 days later) » 

17:12
1
Q: Can Linux do "source MAC based routing?"

Rusty LemurI'm looking for a way in Linux to perform source-MAC based routing. My goal is to have a router with the following routing: echo 100 inbound >> /etc/iproute2/rt_tables ip rule add iif eth0 priority 100 table inbound ip route add default via <myproxy> dev eth1 table inbound echo 200 returntosender >

Why don't you just not send traffic to eth1 that you don't want to go out of eth1 in the first place? If you want to do stuff based on MAC address look into ebtables.
IIRC ebtables only works for bridges. He probably needs to use nftables (to set ct mark based on ethernet addresses and set meta mark (i.e. fwmark) based on the ct mark for the replies). I think a new table (and a different set of the two marks) are needed for each of the MAC address. Is this for dealing with conflicting IP subnets?
Thanks, I'll look into ebtables. I have a proxy connected to the router's eth1 that will operate on the packets before returning them back to the router's eth1 interface.
It's not for dealing with conflicting IP subnets, but for dealing with transparent proxies before my router, where the IP address of the proxies will not be known, but the source MAC addresses will be used to know which instance of the proxy to return the traffic to.
I added an EDIT to my initial post to illustrate why I need the source-mac based routing
Thanks A.B, I've added some IP addresses and more detailed network flow. The routing tables in the OP are an attempt to solve part of the routing, but are not necessary if there is a better way. myproxy will use tproxy or a similar strategy to intercept the traffic, like what is described here: blog.cloudflare.com/how-we-built-spectrum. My main hurdle now is getting myrouter to route back to the correct instance of routerA, since the L3/4 will not indicate which routerA instance to use, but only the L2 MAC where the ingress traffic was received from.
I should also mention that myproxy does not necessarily need to receive the the L3/L4 of the original packet. myrouter could masquerade or otherwise NAT the traffic to myproxy as long as myrouter uses the original L3/4 when it returns traffic to routerA. I don't know if that simplifies or complicates things, but it's not a strict requirement.
Sorry about the initial post having "mygateway" as the via. I hadn't settled on the name "myproxy" yet, and just recently caught it.
Correct, every client will have a unique IP. It may use any one of the available routerAs, but only one. I.e. one client will not use multiple routerAs.
The 3rd point is the crux of my question. How to have nftables store the IP:MAC from the ingress so it can use that MAC for the egress. The rest of my setup I think I will be able to handle once I get that. Is that something you can help me flesh out?
Also, what feature from Linux kernel 5.16 would help with the egress?
A.B
A.B
Reformulate your question with a simpler problem matching ONLY "source MAC based routing" without having a router traversed multiple times for the same packet (or transparent-proxied packet). Currently, RAx sees the same packet twice in the query, and twice in the reply because it also routes the server. That's just an additional problem in the way of the "source MAC based routing" and if I give an answer, I feel compelled to have it working but not to solve multiple other problems (if they are solvable).
btw: I deleted some other comments and did add some information in the chat.
17:25
I'm trying to think how I can simplify the issue. routerA is necessary because it does not own the source IP or destination IP, so its MAC address is the only distinguishing component from the perspective of myrouter. Its existence is the reason I need the source MAC routing. I'm fine with excluding the return traffic from the server.
We could say that return traffic will not route through myrouter, but only through routerA. routerA is proprietary/closed-source, and it will handle seeing the same packet twice. I'm only focused on the "myrouter" part of the equation, to get it to route the packets back to routerA based on the source MAC.
I think if I can understand how to use nftables to map a flow of traffic to the source MAC it originated from, and use that MAC for the forwarding of packets, I can get the rest to work.
17:41
I added a couple of items to the end of the post to hopefully reduce the scope.
17:53
I feel like knowing how to implement this would greatly help:
Pseudo logic for myrouter with eth0 connected to routerA and eth1 connected to myproxy

Packet received on eth0
1. Is packet part of a previously seen flow?
NO: Map flow to the source MAC and continue to step 2
YES: Continue to step 2
2. Forward packet through eth1 to myproxy

Packet received on eth1
1. Look up flow in table to find the target MAC
2. Forward packet through eth0 to the target MAC
 
4 hours later…
21:38
I've reformulated a simpler question here: superuser.com/questions/1714551/…

last day (15 days later) »