sd-ipv4ll.c revision be19c5b5e0c0f78b8429b126936fa15856550a23
/***
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 <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "event-util.h"
#include "list.h"
#include "random-util.h"
#include "refcnt.h"
#include "siphash24.h"
#include "sparse-endian.h"
#include "util.h"
#include "sd-ipv4acd.h"
#include "sd-ipv4ll.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);
}
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;
}