Compare commits

...

5 Commits

Author SHA1 Message Date
Chad Brubaker
081db840be Allow overlap in resolv uid => DNS iface mapping
When multiple rules exist covering a given uid the one added most
recently will be used.

This allows us to handle the simultaneous tuns case where a new tun is
coming online for an already running VPN.

_resolv_clear_iface_for_uid_range now also takes the iface and removes
only that matching (iface, uid range) entry.

Bug: 12134439
Change-Id: I9b9cfcfae2f38c409022a8c76ccadad7e2babd78
2014-03-15 15:29:01 -07:00
Elliott Hughes
04583ce9b9 Upgrade to tzdata2014a.
From the release notes:

  Changes affecting near-future time stamps

    Turkey begins DST on 2014-03-31, not 03-30.  (Thanks to Faruk Pasin
    for the heads-up, and to Tim Parenti for simplifying the update.)

  Changes affecting past time stamps

    Fiji ended DST on 2014-01-19 at 02:00, not the previously-scheduled
    03:00.  (Thanks to Steffen Thorsen.)

    Ukraine switched from Moscow to Eastern European time on 1990-07-01
    (not 1992-01-01), and observed DST during the entire next winter.
    (Thanks to Vladimir in Moscow via Alois Treindl.)

    In 1988 Israel observed DST from 04-10 to 09-04, not 04-09 to
    09-03.  (Thanks to Avigdor Finkelstein.)

(cherry picked from commit 159b28eb46)

Bug: 13193205
Change-Id: I3d302039f7e057a97c9d307ce8d32efa056481ed
2014-03-10 15:23:02 -07:00
Robert Greenwalt
abf91850f9 Merge "Fix dns searchdomain use in gethostbyname." into klp-dev 2014-03-05 18:26:27 +00:00
Elliott Hughes
806f3bd7aa Upgrade to tzdata2013i.
From the release notes:

  Changes affecting near-future time stamps:

    Jordan switches back to standard time at 00:00 on December 20, 2013.
    The 2006-2011 transition schedule is planned to resume in 2014.
    (Thanks to Steffen Thorsen.)

  Changes affecting past time stamps:

    In 2004, Cuba began DST on March 28, not April 4.
    (Thanks to Steffen Thorsen.)

Bug: 13193205
Change-Id: I8f26cc50f6b571804a18ff2113b4a47a22bc56dd
2014-02-25 22:47:29 +00:00
Robert Greenwalt
5fddfb8915 Fix dns searchdomain use in gethostbyname.
Need to load search domain data before we attempt to use it.
This is a cherry pick of an AOSP change c11f6f0f39.

bug:6799630

Change-Id: I4ea1131f06ffdf4037fe67f82af5a0349469b609
2013-12-12 21:34:36 +00:00
4 changed files with 33 additions and 46 deletions

View File

@@ -1852,9 +1852,7 @@ static void _remove_pidiface_info_locked(int pid);
static struct resolv_pidiface_info* _get_pid_iface_info_locked(int pid);
/* remove a resolv_pidiface_info structure from _res_uidiface_list */
static int _remove_uidiface_info_locked(int uid_start, int uid_end);
/* check if a range [low,high] overlaps with any already existing ranges in the uid=>iface map*/
static int _resolv_check_uid_range_overlap_locked(int uid_start, int uid_end);
static int _remove_uidiface_info_locked(const char* iface, int uid_start, int uid_end);
/* get a resolv_uidiface_info structure from _res_uidiface_list with a certain uid */
static struct resolv_uidiface_info* _get_uid_iface_info_locked(int uid);
@@ -2433,11 +2431,11 @@ _resolv_get_pids_associated_interface(int pid, char* buff, int buffLen)
}
static int
_remove_uidiface_info_locked(int uid_start, int uid_end) {
_remove_uidiface_info_locked(const char* ifname, int uid_start, int uid_end) {
struct resolv_uidiface_info* result = _res_uidiface_list.next;
struct resolv_uidiface_info* prev = &_res_uidiface_list;
while (result != NULL && result->uid_start != uid_start && result->uid_end != uid_end) {
while (result != NULL && !(result->uid_start == uid_start && result->uid_end == uid_end &&
!strcmp(result->ifname, ifname))) {
prev = result;
result = result->next;
}
@@ -2461,19 +2459,6 @@ _get_uid_iface_info_locked(int uid)
return result;
}
static int
_resolv_check_uid_range_overlap_locked(int uid_start, int uid_end)
{
struct resolv_uidiface_info* cur = _res_uidiface_list.next;
while (cur != NULL) {
if (cur->uid_start <= uid_end && cur->uid_end >= uid_start) {
return -1;
}
cur = cur->next;
}
return 0;
}
void
_resolv_clear_iface_uid_range_mapping()
{
@@ -2518,28 +2503,21 @@ _resolv_set_iface_for_uid_range(const char* ifname, int uid_start, int uid_end)
return -1;
}
pthread_mutex_lock(&_res_uidiface_list_lock);
//check that we aren't adding an overlapping range
if (!_resolv_check_uid_range_overlap_locked(uid_start, uid_end)) {
uidiface_info = calloc(sizeof(*uidiface_info), 1);
if (uidiface_info) {
uidiface_info->uid_start = uid_start;
uidiface_info->uid_end = uid_end;
int len = sizeof(uidiface_info->ifname);
strncpy(uidiface_info->ifname, ifname, len - 1);
uidiface_info->ifname[len - 1] = '\0';
uidiface_info = calloc(sizeof(*uidiface_info), 1);
if (uidiface_info) {
uidiface_info->uid_start = uid_start;
uidiface_info->uid_end = uid_end;
int len = sizeof(uidiface_info->ifname);
strncpy(uidiface_info->ifname, ifname, len - 1);
uidiface_info->ifname[len - 1] = '\0';
uidiface_info->next = _res_uidiface_list.next;
_res_uidiface_list.next = uidiface_info;
uidiface_info->next = _res_uidiface_list.next;
_res_uidiface_list.next = uidiface_info;
XLOG("_resolv_set_iface_for_uid_range: [%d,%d], iface %s\n", uid_start, uid_end,
ifname);
} else {
XLOG("_resolv_set_iface_for_uid_range failing calloc\n");
rv = -1;
errno = EINVAL;
}
XLOG("_resolv_set_iface_for_uid_range: [%d,%d], iface %s\n", uid_start, uid_end,
ifname);
} else {
XLOG("_resolv_set_iface_for_uid_range range [%d,%d] overlaps\n", uid_start, uid_end);
XLOG("_resolv_set_iface_for_uid_range failing calloc\n");
rv = -1;
errno = EINVAL;
}
@@ -2549,14 +2527,14 @@ _resolv_set_iface_for_uid_range(const char* ifname, int uid_start, int uid_end)
}
int
_resolv_clear_iface_for_uid_range(int uid_start, int uid_end)
_resolv_clear_iface_for_uid_range(const char* ifname, int uid_start, int uid_end)
{
pthread_once(&_res_cache_once, _res_cache_init);
pthread_mutex_lock(&_res_uidiface_list_lock);
int rv = _remove_uidiface_info_locked(uid_start, uid_end);
int rv = _remove_uidiface_info_locked(ifname, uid_start, uid_end);
XLOG("_resolv_clear_iface_for_uid_range: [%d,%d]\n", uid_start, uid_end);
XLOG("_resolv_clear_iface_for_uid_range: [%d,%d] iface %s\n", uid_start, uid_end, ifname);
pthread_mutex_unlock(&_res_uidiface_list_lock);

View File

@@ -272,6 +272,15 @@ res_nsearch(res_state statp,
(dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
int done = 0;
/* Unfortunately we need to load interface info
* (dns servers, search domains) before
* the domain stuff is tried. Will have a better
* fix after thread pools are used as this will
* be loaded once for the thread instead of each
* time a query is tried.
*/
_resolv_populate_res_for_iface(statp);
for (domain = (const char * const *)statp->dnsrch;
*domain && !done;
domain++) {

View File

@@ -79,13 +79,12 @@ extern void _resolv_clear_iface_pid_mapping();
extern int _resolv_get_pids_associated_interface(int pid, char* buff, int buffLen);
/** set a uid range to use the name servers of the specified interface
* If [low,high] overlaps with an already existing rule -1 is returned */
/** set a uid range to use the name servers of the specified interface */
extern int _resolv_set_iface_for_uid_range(const char* ifname, int uid_start, int uid_end);
/* clear a uid range from being associated with an interface
* If the range given is not mapped -1 is returned. */
extern int _resolv_clear_iface_for_uid_range(int uid_start, int uid_end);
/** Remove a mapping added by _resolv_set_iface_for_uid_range.
* If no such rule exists -1 is returned. */
extern int _resolv_clear_iface_for_uid_range(const char* ifname, int uid_start, int uid_end);
/* clear the entire mapping of uid ranges to interfaces. */
extern void _resolv_clear_iface_uid_range_mapping();
@@ -94,6 +93,7 @@ extern void _resolv_clear_iface_uid_range_mapping();
* On error, -1 is returned.
* If no interface is found, 0 is returned and buff is set to empty ('\0').
* If an interface is found, the name is copied to buff and the length of the name is returned.
* If there are multiple rules covering uid the most recently added rule will be returned.
* Arguments: uid The uid to find an interface for
* buff A buffer to copy the result to
* buffLen Length of buff. An interface is at most IF_NAMESIZE in length */

Binary file not shown.