Lines Matching refs:ll
42 #define IPV4LL_DONT_DESTROY(ll) \
43 _cleanup_(sd_ipv4ll_unrefp) _unused_ sd_ipv4ll *_dont_destroy_##ll = sd_ipv4ll_ref(ll)
59 sd_ipv4ll *sd_ipv4ll_ref(sd_ipv4ll *ll) {
60 if (!ll)
63 assert(ll->n_ref >= 1);
64 ll->n_ref++;
66 return ll;
69 sd_ipv4ll *sd_ipv4ll_unref(sd_ipv4ll *ll) {
70 if (!ll)
73 assert(ll->n_ref >= 1);
74 ll->n_ref--;
76 if (ll->n_ref > 0)
79 sd_ipv4acd_unref(ll->acd);
81 free(ll->random_data);
82 free(ll->random_data_state);
83 free(ll);
88 static void ipv4ll_on_acd(sd_ipv4acd *ll, int event, void *userdata);
91 _cleanup_(sd_ipv4ll_unrefp) sd_ipv4ll *ll = NULL;
96 ll = new0(sd_ipv4ll, 1);
97 if (!ll)
100 ll->n_ref = 1;
102 r = sd_ipv4acd_new(&ll->acd);
106 r = sd_ipv4acd_set_callback(ll->acd, ipv4ll_on_acd, ll);
110 *ret = ll;
111 ll = NULL;
116 int sd_ipv4ll_stop(sd_ipv4ll *ll) {
119 assert_return(ll, -EINVAL);
121 r = sd_ipv4acd_stop(ll->acd);
128 int sd_ipv4ll_set_index(sd_ipv4ll *ll, int interface_index) {
129 assert_return(ll, -EINVAL);
131 return sd_ipv4acd_set_index(ll->acd, interface_index);
136 int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr) {
139 assert_return(ll, -EINVAL);
141 if (!ll->random_data) {
149 r = sd_ipv4ll_set_address_seed(ll, (unsigned) htole64(seed));
154 return sd_ipv4acd_set_mac(ll->acd, addr);
157 int sd_ipv4ll_detach_event(sd_ipv4ll *ll) {
158 assert_return(ll, -EINVAL);
160 return sd_ipv4acd_detach_event(ll->acd);
163 int sd_ipv4ll_attach_event(sd_ipv4ll *ll, sd_event *event, int priority) {
166 assert_return(ll, -EINVAL);
168 r = sd_ipv4acd_attach_event(ll->acd, event, priority);
175 int sd_ipv4ll_set_callback(sd_ipv4ll *ll, sd_ipv4ll_cb_t cb, void *userdata) {
176 assert_return(ll, -EINVAL);
178 ll->cb = cb;
179 ll->userdata = userdata;
184 int sd_ipv4ll_get_address(sd_ipv4ll *ll, struct in_addr *address){
185 assert_return(ll, -EINVAL);
188 if (ll->claimed_address == 0)
191 address->s_addr = ll->claimed_address;
196 int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, unsigned seed) {
201 assert_return(ll, -EINVAL);
215 free(ll->random_data);
216 ll->random_data = random_data;
219 free(ll->random_data_state);
220 ll->random_data_state = random_data_state;
226 int sd_ipv4ll_is_running(sd_ipv4ll *ll) {
227 assert_return(ll, false);
229 return sd_ipv4acd_is_running(ll->acd);
249 int sd_ipv4ll_set_address(sd_ipv4ll *ll, const struct in_addr *address) {
252 assert_return(ll, -EINVAL);
256 r = sd_ipv4acd_set_address(ll->acd, address);
260 ll->address = address->s_addr;
265 static int ipv4ll_pick_address(sd_ipv4ll *ll) {
271 assert(ll);
272 assert(ll->random_data);
275 r = random_r(ll->random_data, &random);
279 } while (addr == ll->address ||
285 r = sd_ipv4ll_set_address(ll, &in_addr);
292 int sd_ipv4ll_start(sd_ipv4ll *ll) {
295 assert_return(ll, -EINVAL);
296 assert_return(ll->random_data, -EINVAL);
298 if (ll->address == 0) {
299 r = ipv4ll_pick_address(ll);
304 r = sd_ipv4acd_start(ll->acd);
311 static void ipv4ll_client_notify(sd_ipv4ll *ll, int event) {
312 assert(ll);
314 if (ll->cb)
315 ll->cb(ll, event, ll->userdata);
319 sd_ipv4ll *ll = userdata;
320 IPV4LL_DONT_DESTROY(ll);
324 assert(ll);
328 ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_STOP);
330 ll->claimed_address = 0;
334 ll->claimed_address = ll->address;
335 ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_BIND);
341 if (ll->claimed_address != 0) {
342 ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_CONFLICT);
344 ll->claimed_address = 0;
346 r = ipv4ll_pick_address(ll);
350 r = sd_ipv4acd_start(ll->acd);
363 ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_STOP);