LCOV - code coverage report
Current view: top level - libsystemd-network - ipv4ll-packet.c (source / functions) Hit Total Coverage
Test: systemd test coverage Lines: 22 35 62.9 %
Date: 2015-07-29 18:47:03 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /***
       2             :   This file is part of systemd.
       3             : 
       4             :   Copyright (C) 2014 Axis Communications AB. All rights reserved.
       5             : 
       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.
      10             : 
      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.
      15             : 
      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/>.
      18             : ***/
      19             : #include <arpa/inet.h>
      20             : 
      21             : #include "util.h"
      22             : #include "ipv4ll-internal.h"
      23             : 
      24           3 : void arp_packet_init(struct ether_arp *arp) {
      25           3 :         assert(arp);
      26             : 
      27           3 :         memzero(arp, sizeof(struct ether_arp));
      28             :         /* Header */
      29           3 :         arp->ea_hdr.ar_hrd = htons(ARPHRD_ETHER); /* HTYPE */
      30           3 :         arp->ea_hdr.ar_pro = htons(ETHERTYPE_IP); /* PTYPE */
      31           3 :         arp->ea_hdr.ar_hln = ETH_ALEN; /* HLEN */
      32           3 :         arp->ea_hdr.ar_pln = sizeof arp->arp_spa; /* PLEN */
      33           3 :         arp->ea_hdr.ar_op = htons(ARPOP_REQUEST); /* REQUEST */
      34           3 : }
      35             : 
      36           2 : void arp_packet_probe(struct ether_arp *arp, be32_t pa, const struct ether_addr *ha) {
      37           2 :         assert(ha);
      38             : 
      39           2 :         arp_packet_init(arp);
      40           2 :         memcpy(arp->arp_sha, ha, ETH_ALEN);
      41           2 :         memcpy(arp->arp_tpa, &pa, sizeof(pa));
      42           2 : }
      43             : 
      44           1 : void arp_packet_announcement(struct ether_arp *arp, be32_t pa, const struct ether_addr *ha) {
      45           1 :         assert(ha);
      46             : 
      47           1 :         arp_packet_init(arp);
      48           1 :         memcpy(arp->arp_sha, ha, ETH_ALEN);
      49           1 :         memcpy(arp->arp_tpa, &pa, sizeof(pa));
      50           1 :         memcpy(arp->arp_spa, &pa, sizeof(pa));
      51           1 : }
      52             : 
      53           0 : int arp_packet_verify_headers(struct ether_arp *arp) {
      54           0 :         assert(arp);
      55             : 
      56           0 :         if (arp->ea_hdr.ar_hrd != htons(ARPHRD_ETHER)) {
      57           0 :                 log_ipv4ll(NULL, "ignoring packet: header is not ARPHRD_ETHER");
      58           0 :                 return -EINVAL;
      59             :         }
      60           0 :         if (arp->ea_hdr.ar_pro != htons(ETHERTYPE_IP)) {
      61           0 :                 log_ipv4ll(NULL, "ignoring packet: protocol is not ETHERTYPE_IP");
      62           0 :                 return -EINVAL;
      63             :         }
      64           0 :         if (arp->ea_hdr.ar_op != htons(ARPOP_REQUEST) &&
      65           0 :             arp->ea_hdr.ar_op != htons(ARPOP_REPLY)) {
      66           0 :                 log_ipv4ll(NULL, "ignoring packet: operation is not ARPOP_REQUEST or ARPOP_REPLY");
      67           0 :                 return -EINVAL;
      68             :         }
      69             : 
      70           0 :         return 0;
      71             : }

Generated by: LCOV version 1.11