Home | History | Annotate | Line # | Download | only in rump_dhcpclient
      1  1.1  pooka /*
      2  1.1  pooka  * dhcpcd - DHCP client daemon
      3  1.1  pooka  * Copyright (c) 2006-2008 Roy Marples <roy (at) marples.name>
      4  1.1  pooka  *
      5  1.1  pooka  * Redistribution and use in source and binary forms, with or without
      6  1.1  pooka  * modification, are permitted provided that the following conditions
      7  1.1  pooka  * are met:
      8  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
      9  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     10  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     13  1.1  pooka  *
     14  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     15  1.1  pooka  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  1.1  pooka  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     17  1.1  pooka  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     18  1.1  pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     19  1.1  pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     20  1.1  pooka  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     21  1.1  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     22  1.1  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     23  1.1  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     24  1.1  pooka  * SUCH DAMAGE.
     25  1.1  pooka  */
     26  1.1  pooka 
     27  1.1  pooka #ifndef BPF_ETHCOOK
     28  1.1  pooka # define BPF_ETHCOOK 0
     29  1.1  pooka #endif
     30  1.1  pooka #ifndef BPF_WHOLEPACKET
     31  1.1  pooka # define BPF_WHOLEPACKET ~0U
     32  1.1  pooka #endif
     33  1.2  joerg static const struct bpf_insn arp_bpf_filter [] = {
     34  1.1  pooka #ifndef BPF_SKIPTYPE
     35  1.1  pooka 	/* Make sure this is an ARP packet... */
     36  1.1  pooka 	BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12),
     37  1.1  pooka 	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_ARP, 0, 3),
     38  1.1  pooka #endif
     39  1.1  pooka 	/* Make sure this is an ARP REQUEST... */
     40  1.1  pooka 	BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20 + BPF_ETHCOOK),
     41  1.1  pooka 	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ARPOP_REQUEST, 2, 0),
     42  1.1  pooka 	/* or ARP REPLY... */
     43  1.1  pooka 	BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20 + BPF_ETHCOOK),
     44  1.1  pooka 	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ARPOP_REPLY, 0, 1),
     45  1.1  pooka 	/* If we passed all the tests, ask for the whole packet. */
     46  1.1  pooka 	BPF_STMT(BPF_RET + BPF_K, BPF_WHOLEPACKET),
     47  1.1  pooka 	/* Otherwise, drop it. */
     48  1.1  pooka 	BPF_STMT(BPF_RET + BPF_K, 0),
     49  1.1  pooka };
     50  1.1  pooka static const size_t arp_bpf_filter_len =
     51  1.1  pooka     sizeof(arp_bpf_filter) / sizeof(arp_bpf_filter[0]);
     52  1.1  pooka 
     53  1.1  pooka 
     54  1.1  pooka /* dhcp_bpf_filter taken from bpf.c in dhcp-3.1.0
     55  1.1  pooka  *
     56  1.1  pooka  * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
     57  1.1  pooka  * Copyright (c) 1996-2003 by Internet Software Consortium
     58  1.1  pooka  *
     59  1.1  pooka  * Permission to use, copy, modify, and distribute this software for any
     60  1.1  pooka  * purpose with or without fee is hereby granted, provided that the above
     61  1.1  pooka  * copyright notice and this permission notice appear in all copies.
     62  1.1  pooka  *
     63  1.1  pooka  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
     64  1.1  pooka  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     65  1.1  pooka  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
     66  1.1  pooka  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     67  1.1  pooka  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     68  1.1  pooka  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
     69  1.1  pooka  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     70  1.1  pooka  *
     71  1.1  pooka  *   Internet Systems Consortium, Inc.
     72  1.1  pooka  *   950 Charter Street
     73  1.1  pooka  *   Redwood City, CA 94063
     74  1.1  pooka  *   <info (at) isc.org>
     75  1.1  pooka  *   http://www.isc.org/
     76  1.1  pooka  */
     77  1.1  pooka 
     78  1.2  joerg static const struct bpf_insn dhcp_bpf_filter [] = {
     79  1.1  pooka #ifndef BPF_SKIPTYPE
     80  1.1  pooka 	/* Make sure this is an IP packet... */
     81  1.1  pooka 	BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12),
     82  1.1  pooka 	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8),
     83  1.1  pooka #endif
     84  1.1  pooka 	/* Make sure it's a UDP packet... */
     85  1.1  pooka 	BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23 + BPF_ETHCOOK),
     86  1.1  pooka 	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6),
     87  1.1  pooka 	/* Make sure this isn't a fragment... */
     88  1.1  pooka 	BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20 + BPF_ETHCOOK),
     89  1.1  pooka 	BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0),
     90  1.1  pooka 	/* Get the IP header length... */
     91  1.1  pooka 	BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14 + BPF_ETHCOOK),
     92  1.1  pooka 	/* Make sure it's to the right port... */
     93  1.1  pooka 	BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16 + BPF_ETHCOOK),
     94  1.1  pooka 	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, DHCP_CLIENT_PORT, 0, 1),
     95  1.1  pooka 	/* If we passed all the tests, ask for the whole packet. */
     96  1.1  pooka 	BPF_STMT(BPF_RET + BPF_K, BPF_WHOLEPACKET),
     97  1.1  pooka 	/* Otherwise, drop it. */
     98  1.1  pooka 	BPF_STMT(BPF_RET + BPF_K, 0),
     99  1.1  pooka };
    100  1.1  pooka static const size_t dhcp_bpf_filter_len =
    101  1.1  pooka     sizeof(dhcp_bpf_filter) / sizeof(dhcp_bpf_filter[0]);
    102