Tanks to Thaller; you made us discovering treasure of NetworkManager. Without your suggestion I probably never take the time to READ the man, and this workaroung.
So now to avoid wasting your time with obsolete informartion in this man, be aware that envireonment variable IP4_GATEWAY , proposed in the man is NEVER valuated, what ever you do in /etc/NetworkManager/dispatcher.d/ subdirectories.
Fortunately when these script are running, for example at pre-up mode, the interface is already up, and the gateway provided by DHCP server is already there too.
So a concrete solution is:
1] put your extra route in let's say:
/etc/NetworkManager/DHCP_additional_routes
example:
8.8.4.4 32 enp6s18
8.8.8.8 32 enp6s19
(target mask interface)
2] in the a script let's say manage_additional_route under /etc/NetworkManager/dispatcher.d/pre-up.d/
You will be able to get a value for IP4_GATEWAY:
#!/bin/bash
INTERFACE="$1"
ACTION="$2"
DEFROUTE=`ip route show | grep $INTERFACE | grep default`
IP4_GATEWAY=`echo $DEFROUTE | awk '{print $3}'`
grep "$INTERFACE" /etc/NetworkManager/DHCP_additional_routes| while read LINE0
do
P1=`echo $LINE0| awk '{print $1}'`
P2=`echo $LINE0| awk '{print $2}'`
P3=`echo $LINE0| awk '{print $3}'`
ip route add $P1/$P2 via $IP4_GATEWAY
done
I needed that to manage failover between 2 wan interfaces getting address from DHCP server. With the method "canary" : you test a ping on the target described in DHCP_additionnal_route, which can be routed exclusively by the interface given above, so you know if an interface is up or down