/* Create a socket for the VRF. */
int vrf_socket(int domain, int type, int protocol, vrf_id_t vrf_id)
{
- int ret = -1;
+ int ret, save_errno, ret2;
+ ret = vrf_switch_to_netns(vrf_id);
+ if (ret < 0)
+ zlog_err("%s: Can't switch to VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
ret = socket(domain, type, protocol);
-
+ save_errno = errno;
+ ret2 = vrf_switchback_to_initial();
+ if (ret2 < 0)
+ zlog_err("%s: Can't switchback from VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
+ errno = save_errno;
return ret;
}
else
return VRF_DEFAULT_INTERNAL;
}
+
+int vrf_getaddrinfo(const char *node, const char *service,
+ const struct addrinfo *hints,
+ struct addrinfo **res, vrf_id_t vrf_id)
+{
+ int ret, ret2, save_errno;
+
+ ret = vrf_switch_to_netns(vrf_id);
+ if (ret < 0)
+ zlog_err("%s: Can't switch to VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
+ ret = getaddrinfo(node, service, hints, res);
+ save_errno = errno;
+ ret2 = vrf_switchback_to_initial();
+ if (ret2 < 0)
+ zlog_err("%s: Can't switchback from VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
+ errno = save_errno;
+ return ret;
+}
+
+int vrf_sockunion_socket(const union sockunion *su, vrf_id_t vrf_id)
+{
+ int ret, save_errno, ret2;
+
+ ret = vrf_switch_to_netns(vrf_id);
+ if (ret < 0)
+ zlog_err("%s: Can't switch to VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
+ ret = sockunion_socket(su);
+ save_errno = errno;
+ ret2 = vrf_switchback_to_initial();
+ if (ret2 < 0)
+ zlog_err("%s: Can't switchback from VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
+ errno = save_errno;
+ return ret;
+}
extern int vrf_switch_to_netns(vrf_id_t vrf_id);
extern int vrf_switchback_to_initial(void);
+/* VRF ioctl operations */
+extern int vrf_getaddrinfo(const char *node, const char *service,
+ const struct addrinfo *hints,
+ struct addrinfo **res, vrf_id_t vrf_id);
+extern int vrf_sockunion_socket(const union sockunion *su, vrf_id_t vrf_id);
+/* VRF switch from NETNS */
+extern int vrf_switch_to_netns(vrf_id_t vrf_id);
+extern int vrf_switchback_to_initial(void);
+
/* used by NS when vrf backend is NS.
* Notify a change in the VRF ID of the VRF
*/