2 This file is part of systemd.
4 Copyright (C) 2014 Axis Communications AB. All rights reserved.
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 #include <arpa/inet.h>
22 #include "ipv4ll-internal.h"
24 void arp_packet_init(struct ether_arp *arp) {
27 memzero(arp, sizeof(struct ether_arp));
29 arp->ea_hdr.ar_hrd = htons(ARPHRD_ETHER); /* HTYPE */
30 arp->ea_hdr.ar_pro = htons(ETHERTYPE_IP); /* PTYPE */
31 arp->ea_hdr.ar_hln = ETH_ALEN; /* HLEN */
32 arp->ea_hdr.ar_pln = sizeof arp->arp_spa; /* PLEN */
33 arp->ea_hdr.ar_op = htons(ARPOP_REQUEST); /* REQUEST */
36 void arp_packet_probe(struct ether_arp *arp, be32_t pa, const struct ether_addr *ha) {
40 memcpy(arp->arp_sha, ha, ETH_ALEN);
41 memcpy(arp->arp_tpa, &pa, sizeof(pa));
44 void arp_packet_announcement(struct ether_arp *arp, be32_t pa, const struct ether_addr *ha) {
48 memcpy(arp->arp_sha, ha, ETH_ALEN);
49 memcpy(arp->arp_tpa, &pa, sizeof(pa));
50 memcpy(arp->arp_spa, &pa, sizeof(pa));
53 int arp_packet_verify_headers(struct ether_arp *arp) {
56 if (arp->ea_hdr.ar_hrd != htons(ARPHRD_ETHER)) {
57 log_ipv4ll(NULL, "ignoring packet: header is not ARPHRD_ETHER");
60 if (arp->ea_hdr.ar_pro != htons(ETHERTYPE_IP)) {
61 log_ipv4ll(NULL, "ignoring packet: protocol is not ETHERTYPE_IP");
64 if (arp->ea_hdr.ar_op != htons(ARPOP_REQUEST) &&
65 arp->ea_hdr.ar_op != htons(ARPOP_REPLY)) {
66 log_ipv4ll(NULL, "ignoring packet: operation is not ARPOP_REQUEST or ARPOP_REPLY");