Add marking of DNS sockets for mark based routing
Adds an extra mark parameter to android_getaddrinfoforiface, android_gethostbyaddrforiface and android_gethostbynameforiface that if set will cause all packets sent by DNS requests to have that mark Change-Id: I6f72390e4ce5bfc3cc73183f9b2fb3705a11685f
This commit is contained in:
@@ -806,4 +806,11 @@ void res_setiface(res_state statp, const char* iface)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void res_setmark(res_state statp, int mark)
|
||||
{
|
||||
if (statp != NULL) {
|
||||
statp->_mark = mark;
|
||||
}
|
||||
}
|
||||
#endif /* ANDROID_CHANGES */
|
||||
|
@@ -762,10 +762,13 @@ send_vc(res_state statp,
|
||||
if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
|
||||
struct sockaddr_storage peer;
|
||||
socklen_t size = sizeof peer;
|
||||
|
||||
int old_mark;
|
||||
int mark_size = sizeof(old_mark);
|
||||
if (getpeername(statp->_vcsock,
|
||||
(struct sockaddr *)(void *)&peer, &size) < 0 ||
|
||||
!sock_eq((struct sockaddr *)(void *)&peer, nsap)) {
|
||||
!sock_eq((struct sockaddr *)(void *)&peer, nsap) ||
|
||||
getsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &old_mark, &mark_size) < 0 ||
|
||||
old_mark != statp->_mark) {
|
||||
res_nclose(statp);
|
||||
statp->_flags &= ~RES_F_VC;
|
||||
}
|
||||
@@ -795,6 +798,14 @@ send_vc(res_state statp,
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
if (statp->_mark != 0) {
|
||||
if (setsockopt(statp->_vcsock, SOL_SOCKET,
|
||||
SO_MARK, &statp->_mark, sizeof(statp->_mark)) < 0) {
|
||||
*terrno = errno;
|
||||
Perror(statp, stderr, "setsockopt", errno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
errno = 0;
|
||||
if (random_bind(statp->_vcsock,nsap->sa_family) < 0) {
|
||||
*terrno = errno;
|
||||
@@ -1070,6 +1081,14 @@ send_dg(res_state statp,
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (statp->_mark != 0) {
|
||||
if (setsockopt(EXT(statp).nssocks[ns], SOL_SOCKET,
|
||||
SO_MARK, &(statp->_mark), sizeof(statp->_mark)) < 0) {
|
||||
res_nclose(statp);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#ifndef CANNOT_CONNECT_DGRAM
|
||||
/*
|
||||
* On a 4.3BSD+ machine (client and server,
|
||||
@@ -1097,6 +1116,7 @@ send_dg(res_state statp,
|
||||
#endif /* !CANNOT_CONNECT_DGRAM */
|
||||
Dprint(statp->options & RES_DEBUG,
|
||||
(stdout, ";; new DG socket\n"))
|
||||
|
||||
}
|
||||
s = EXT(statp).nssocks[ns];
|
||||
#ifndef CANNOT_CONNECT_DGRAM
|
||||
|
Reference in New Issue
Block a user