sd-ipv4ll.c revision 0c28d28834f71e74d5a2d8bcfb19938a34396036
/***
This file is part of systemd.
Copyright (C) 2014 Axis Communications AB. All rights reserved.
Copyright (C) 2015 Tom Gundersen
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sd-ipv4acd.h"
#include "sd-ipv4ll.h"
#include "alloc-util.h"
#include "event-util.h"
#include "in-addr-util.h"
#include "list.h"
#include "random-util.h"
#include "refcnt.h"
#include "siphash24.h"
#include "sparse-endian.h"
#include "util.h"
#define IPV4LL_NETWORK 0xA9FE0000L
#define IPV4LL_NETMASK 0xFFFF0000L
#define IPV4LL_DONT_DESTROY(ll) \
struct sd_ipv4ll {
unsigned n_ref;
struct random_data *random_data;
char *random_data_state;
/* External */
void* userdata;
};
if (!ll)
return NULL;
return ll;
}
if (!ll)
return NULL;
return NULL;
return NULL;
}
int r;
if (!ll)
return -ENOMEM;
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
int r;
if (r < 0)
return r;
return 0;
}
}
int r;
if (!ll->random_data) {
/* If no random data is set, generate some from the MAC */
assert_cc(sizeof(unsigned) <= 8);
if (r < 0)
return r;
}
}
}
int r;
if (r < 0)
return r;
return 0;
}
return 0;
}
if (ll->claimed_address == 0)
return -ENOENT;
return 0;
}
int r;
if (!random_data)
return -ENOMEM;
if (!random_data_state)
return -ENOMEM;
if (r < 0)
return r;
random_data = NULL;
return 0;
}
assert_return(ll, false);
}
return false;
return false;
return true;
}
int r;
if (r < 0)
return r;
return 0;
}
int r;
do {
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
int r;
r = ipv4ll_pick_address(ll);
if (r < 0)
return r;
}
if (r < 0)
return r;
return 0;
}
}
int r;
switch (event) {
case SD_IPV4ACD_EVENT_STOP:
ll->claimed_address = 0;
break;
case SD_IPV4ACD_EVENT_BIND:
break;
/* if an address was already bound we must call up to the
user to handle this, otherwise we just try again */
if (ll->claimed_address != 0) {
ll->claimed_address = 0;
} else {
r = ipv4ll_pick_address(ll);
if (r < 0)
goto error;
if (r < 0)
goto error;
}
break;
default:
assert_not_reached("Invalid IPv4ACD event.");
}
return;
}