Hi,

On Mon, Aug 22, 2022 at 02:55:09PM +0200, Kristof Provost wrote:
> > Now, back to FreeBSD.
> >
> >   - our code does not try to set metrics on FreeBSD
> >   - my reading of route(8) does not show me anything in that direction
> >     (metric, preference, administrative distance, ...)
> >   - I do not understand FreeBSD internals well enough to know whether
> >     it can be done at all, or not.
> >
> It???s rather poorly (i.e. not) documented, but it is possible to set a 
> route metric. It???s called a ???weight???, and not actually mentioned 
> in the man page. Or shown in netstat output.
> 
> But:
> 
>       $ sudo route add 172.16.2.0/24 10.0.2.1
>       add net 172.16.2.0: gateway 10.0.2.1
>       $ sudo route add 172.16.2.0/24 -weight 2 10.0.2.254
>       add net 172.16.2.0: gateway 10.0.2.254

Oh, this is interesting, and good to know.

What is the default weight?  "1"?

> So we can add multiple routes for the same network, as long as they have 
> a different gateway.
> 
> The usual `netstat -rn` doesn???t show the weight. You have to use the 
> json/xml output to get it:
> 
>       $ netstat -rn --libxo json | jq
>       ???
>                {
>                  "destination": "172.16.2.0/24",
>                  "gateway": "10.0.2.1",
>                  "flags": "UGS",
>                  "flags_pretty": [
>                    "up",
>                    "gateway",
>                    "static"
>                  ],
>                  "weight": 1,
>                  "interface-name": "bnxt0"
>                },

Interesting :-)

[..]
> A higher weight gives a higher priority, so that???s the opposite of 
> what Linux does with metric, I believe.

Right.  Linux metrics are "lower is better", like a routing protocol 
cost would do.

[..]
> If I???m understanding everything correctly it should be relatively 
> simple to extend networking_freebsd.c to also set a weight for each 
> route it installs.
> We???d have to convert the metric into a weight, which I think we could 
> do as `weight = RT_MAX_WEIGHT - metric` (RT_MAX_WEIGHT is 16777215 /* 3 
> bytes */).
> 
> Can you try this?

Looks good, might work :-).

Will give this a try as soon as time permits - next 2-3 weeks might not 
work out.

gert
-- 
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             g...@greenie.muc.de

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to