dhcp-network.c revision 58587a7a0c3bf5595190486781d3bbc00654c6ef
/***
This file is part of systemd.
Copyright (C) 2013 Intel Corporation. All rights reserved.
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 <errno.h>
#include <string.h>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <stdio.h>
#include <unistd.h>
#include "socket-util.h"
#include "dhcp-internal.h"
struct sock_filter filter[] = {
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, offsetof(DHCPPacket, ip.frag_off)), /* A <- Flags + Fragment offset */
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, DHCP_PORT_CLIENT, 1, 0), /* UDP destination port == DHCP client port ? */
BPF_STMT(BPF_LD + BPF_IMM, htobe32(*((unsigned int *) &mac_addr))), /* A <- 4 bytes of client's MAC */
BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(DHCPPacket, dhcp.chaddr)), /* A <- 4 bytes of MAC from dhcp.chaddr */
BPF_STMT(BPF_LD + BPF_IMM, htobe16(*((unsigned short *) (((char *) &mac_addr) + 4)))), /* A <- remainder of client's MAC */
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, offsetof(DHCPPacket, dhcp.chaddr) + 4), /* A <- remainder of MAC from dhcp.chaddr */
};
struct sock_fprog fprog = {
};
_cleanup_close_ int s = -1;
int r, on = 1;
if (s < 0)
return -errno;
if (r < 0)
return -errno;
if (r < 0)
return -errno;
if (r < 0)
return -errno;
r = s;
s = -1;
return r;
}
union sockaddr_union src = {
};
_cleanup_close_ int s = -1;
int r, tos = IPTOS_CLASS_CS6;
if (s < 0)
return -errno;
if (r < 0)
return -errno;
if (address == INADDR_ANY) {
int on = 1;
if (r < 0)
return -errno;
if (r < 0)
return -errno;
if (r < 0)
return -errno;
}
if (r < 0)
return -errno;
r = s;
s = -1;
return r;
}
int r;
if (r < 0)
return -errno;
return 0;
}
union sockaddr_union dest = {
};
int r;
assert(s >= 0);
if (r < 0)
return -errno;
return 0;
}