1*1c60b9acSAndroid Build Coastguard Worker# Lws routing 2*1c60b9acSAndroid Build Coastguard Worker 3*1c60b9acSAndroid Build Coastguard Workerlws is mainly built around POSIX sockets and operates from the 4*1c60b9acSAndroid Build Coastguard Workerinformation available from those. But in some cases, it needs to go 5*1c60b9acSAndroid Build Coastguard Workera step further and monitor and understand the device routing table. 6*1c60b9acSAndroid Build Coastguard Worker 7*1c60b9acSAndroid Build Coastguard Worker## Recognizing loss of routability 8*1c60b9acSAndroid Build Coastguard Worker 9*1c60b9acSAndroid Build Coastguard WorkerOn mobile devices, switching between interfaces and losing / regaining 10*1c60b9acSAndroid Build Coastguard Workerconnections quickly is a given. But POSIX sockets do not act like 11*1c60b9acSAndroid Build Coastguard Workerthat, the socket remains connected until something times it out if it 12*1c60b9acSAndroid Build Coastguard Workerno longer has a route to its peer, and the tcp timeouts can be in the 13*1c60b9acSAndroid Build Coastguard Workerorder of minutes. 14*1c60b9acSAndroid Build Coastguard Worker 15*1c60b9acSAndroid Build Coastguard WorkerIn order to do better, lws must monitor and understand how the routing 16*1c60b9acSAndroid Build Coastguard Workertable relates to existing connections, dynamically. 17*1c60b9acSAndroid Build Coastguard Worker 18*1c60b9acSAndroid Build Coastguard Worker## Linux: netlink 19*1c60b9acSAndroid Build Coastguard Worker 20*1c60b9acSAndroid Build Coastguard WorkerFor linux-based devices you can build in netlink-based route monitoring 21*1c60b9acSAndroid Build Coastguard Workerwith `-DLWS_WITH_NETLINK=1`, lws aquires a copy of the routing table 22*1c60b9acSAndroid Build Coastguard Workerwhen the context / pt starts up and modifies it according to netlink 23*1c60b9acSAndroid Build Coastguard Workermessages from then on. 24*1c60b9acSAndroid Build Coastguard Worker 25*1c60b9acSAndroid Build Coastguard WorkerOn Linux routing table events do not take much care about backing out 26*1c60b9acSAndroid Build Coastguard Workerchanges made on interface up by, eg, NetworkManager. So lws also 27*1c60b9acSAndroid Build Coastguard Workermonitors for link / interface down to remove the related routes. 28*1c60b9acSAndroid Build Coastguard Worker 29*1c60b9acSAndroid Build Coastguard Worker## Actions in lws based on routing table 30*1c60b9acSAndroid Build Coastguard Worker 31*1c60b9acSAndroid Build Coastguard WorkerBoth server and client connections now store their peer sockaddr in the 32*1c60b9acSAndroid Build Coastguard Workerwsi, and when the routing table changes, all active wsi on a pt are 33*1c60b9acSAndroid Build Coastguard Workerchecked against the routing table to confirm the peer is still 34*1c60b9acSAndroid Build Coastguard Workerroutable. 35*1c60b9acSAndroid Build Coastguard Worker 36*1c60b9acSAndroid Build Coastguard WorkerFor example if there is no net route matching the peer and no gateway, 37*1c60b9acSAndroid Build Coastguard Workerthe connection is invalidated and closed. Similarly, if we are 38*1c60b9acSAndroid Build Coastguard Workerremoving the highest priority gateway route, all connections to a peer 39*1c60b9acSAndroid Build Coastguard Workerwithout a net route match are invalidated. However connections with 40*1c60b9acSAndroid Build Coastguard Workeran unaffected matching net route like 127.0.0.0/8 are left alone. 41*1c60b9acSAndroid Build Coastguard Worker 42*1c60b9acSAndroid Build Coastguard Worker## Intergration to other subsystems 43*1c60b9acSAndroid Build Coastguard Worker 44*1c60b9acSAndroid Build Coastguard WorkerIf SMD is built in, on any route change a NETWORK message 45*1c60b9acSAndroid Build Coastguard Worker`{"rt":"add|del"}` is issued. 46*1c60b9acSAndroid Build Coastguard Worker 47*1c60b9acSAndroid Build Coastguard WorkerIf SMD is built in, on any route change involving a gateway, a NETWORK 48*1c60b9acSAndroid Build Coastguard Workermessage `{"trigger":"cpdcheck", "src":"gw-change"}` is issued. If 49*1c60b9acSAndroid Build Coastguard WorkerCaptive Portal Detection is built in, this will cause a new captive 50*1c60b9acSAndroid Build Coastguard Workerportal detection sequence. 51*1c60b9acSAndroid Build Coastguard Worker 52