d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog This file is part of systemd.
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog Copyright (C) 2014 Axis Communications AB. All rights reserved.
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog systemd is free software; you can redistribute it and/or modify it
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog under the terms of the GNU Lesser General Public License as published by
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog the Free Software Foundation; either version 2.1 of the License, or
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog (at your option) any later version.
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog systemd is distributed in the hope that it will be useful, but
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog WITHOUT ANY WARRANTY; without even the implied warranty of
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog Lesser General Public License for more details.
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog You should have received a copy of the GNU Lesser General Public License
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog along with systemd; If not, see <http://www.gnu.org/licenses/>.
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskogstatic int basic_request_handler_bind = 0;
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskogstatic int basic_request_handler_stop = 0;
89ca10c6a61309d84d54c5dc5a295387ce39e610Lennart Poetteringstatic void* basic_request_handler_userdata = (void*)0xCABCAB;
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskogstatic void basic_request_handler(sd_ipv4ll *ll, int event, void *userdata) {
89ca10c6a61309d84d54c5dc5a295387ce39e610Lennart Poettering assert_se(userdata == basic_request_handler_userdata);
996d16975b4d802335188a3be2bbc3635c1287f3Tom Gundersenstatic int arp_network_send_raw_socket(int fd, int ifindex,
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog if (send(fd, arp, sizeof(struct ether_arp), 0) < 0)
996d16975b4d802335188a3be2bbc3635c1287f3Tom Gundersen return arp_network_send_raw_socket(fd, ifindex, &ea);
996d16975b4d802335188a3be2bbc3635c1287f3Tom Gundersen return arp_network_send_raw_socket(fd, ifindex, &ea);
996d16975b4d802335188a3be2bbc3635c1287f3Tom Gundersenint arp_network_bind_raw_socket(int index, be32_t address, const struct ether_addr *eth_mac) {
996d16975b4d802335188a3be2bbc3635c1287f3Tom Gundersen if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0, test_fd) < 0)
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskogstatic void test_public_api_setters(sd_event *e) {
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}};
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_attach_event(NULL, NULL, 0) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_attach_event(ll, e, 0) == 0);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_attach_event(ll, e, 0) == -EBUSY);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_callback(NULL, NULL, NULL) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_callback(ll, NULL, NULL) == 0);
129dc1b489d924d28956b09a06f03d7607beb8adTom Gundersen assert_se(sd_ipv4ll_set_address(ll, &address) == -EINVAL);
129dc1b489d924d28956b09a06f03d7607beb8adTom Gundersen address.s_addr |= htobe32(169U << 24 | 254U << 16);
129dc1b489d924d28956b09a06f03d7607beb8adTom Gundersen assert_se(sd_ipv4ll_set_address(ll, &address) == -EINVAL);
129dc1b489d924d28956b09a06f03d7607beb8adTom Gundersen assert_se(sd_ipv4ll_set_address(ll, &address) == -EINVAL);
129dc1b489d924d28956b09a06f03d7607beb8adTom Gundersen assert_se(sd_ipv4ll_set_address(ll, &address) == 0);
129dc1b489d924d28956b09a06f03d7607beb8adTom Gundersen assert_se(sd_ipv4ll_set_address(ll, &address) == -EINVAL);
5625be76c755c99f8b41d7fe84156ebc732b454cRonny Chevalier assert_se(sd_ipv4ll_set_address_seed(NULL, seed) == -EINVAL);
5625be76c755c99f8b41d7fe84156ebc732b454cRonny Chevalier assert_se(sd_ipv4ll_set_address_seed(ll, seed) == 0);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_mac(NULL, NULL) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_mac(ll, NULL) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_mac(ll, &mac_addr) == 0);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_index(NULL, -1) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_index(ll, -1) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_index(ll, -99) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_index(ll, 1) == 0);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_index(ll, 99) == 0);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_unref(ll) == NULL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskogstatic void test_basic_request(sd_event *e) {
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}};
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_start(ll) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_attach_event(ll, e, 0) == 0);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_start(ll) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_mac(ll, &mac_addr) == 0);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_start(ll) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_callback(ll, basic_request_handler,
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_start(ll) == -EINVAL);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_set_index(ll, 1) == 0);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_start(ll) == -EBUSY);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(read(test_fd[1], &arp, sizeof(struct ether_arp)) == sizeof(struct ether_arp));
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(read(test_fd[1], &arp, sizeof(struct ether_arp)) == sizeof(struct ether_arp));
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(read(test_fd[1], &arp, sizeof(struct ether_arp)) == sizeof(struct ether_arp));
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(basic_request_handler_bind == 1);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(basic_request_handler_stop == 1);
d9bf4f8c6c47b8620ffa1a056208eb15118b78d5Umut Tezduyar Lindskog assert_se(sd_ipv4ll_unref(ll) == NULL);