+static void add_host_route(int family, int index, const char *gateway,
+ enum connman_service_type service_type)
+{
+ switch (family) {
+ case AF_INET:
+ if (g_strcmp0(gateway, "0.0.0.0") != 0) {
+ /*
+ * We must not set route to the phy dev gateway in
+ * VPN link. The packets to VPN link might be routed
+ * back to itself and not routed into phy link gateway.
+ */
+ if (service_type != CONNMAN_SERVICE_TYPE_VPN)
+ connman_inet_add_host_route(index, gateway,
+ NULL);
+ } else {
+ /*
+ * Add host route to P-t-P link so that services can
+ * be moved around and we can have some link to P-t-P
+ * network (although those P-t-P links have limited
+ * usage if default route is not directed to them)
+ */
+ char *dest;
+ if (connman_inet_get_dest_addr(index, &dest) == 0) {
+ connman_inet_add_host_route(index, dest, NULL);
+ g_free(dest);
+ }
+ }
+ break;
+
+ case AF_INET6:
+ if (g_strcmp0(gateway, "::") != 0) {
+ if (service_type != CONNMAN_SERVICE_TYPE_VPN)
+ connman_inet_add_ipv6_host_route(index,
+ gateway, NULL);
+ } else {
+ /* P-t-P link, add route to destination */
+ char *dest;
+ if (connman_inet_ipv6_get_dest_addr(index,
+ &dest) == 0) {
+ connman_inet_add_ipv6_host_route(index, dest,
+ NULL);
+ g_free(dest);
+ }
+ }
+ break;
+ }
+}
+