| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ipkdb_ipkdb.c,v 1.26 2009/04/12 22:37:50 elad Exp $ */ | | 1 | /* $NetBSD: ipkdb_ipkdb.c,v 1.27 2009/10/02 22:05:52 elad Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) 1993-2000 Wolfgang Solfrank. | | 4 | * Copyright (C) 1993-2000 Wolfgang Solfrank. |
5 | * Copyright (C) 1993-2000 TooLs GmbH. | | 5 | * Copyright (C) 1993-2000 TooLs GmbH. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | | 22 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR |
23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
25 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | | 25 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | | 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | | 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | 28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | | 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | | 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include <sys/cdefs.h> | | 34 | #include <sys/cdefs.h> |
35 | __KERNEL_RCSID(0, "$NetBSD: ipkdb_ipkdb.c,v 1.26 2009/04/12 22:37:50 elad Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: ipkdb_ipkdb.c,v 1.27 2009/10/02 22:05:52 elad Exp $"); |
36 | | | 36 | |
37 | #include "opt_ipkdb.h" | | 37 | #include "opt_ipkdb.h" |
38 | | | 38 | |
39 | #include <sys/param.h> | | 39 | #include <sys/param.h> |
40 | #include <sys/socket.h> | | 40 | #include <sys/socket.h> |
41 | #include <sys/mbuf.h> | | 41 | #include <sys/mbuf.h> |
42 | #include <sys/reboot.h> | | 42 | #include <sys/reboot.h> |
43 | #include <sys/systm.h> | | 43 | #include <sys/systm.h> |
44 | #include <sys/kauth.h> | | 44 | #include <sys/kauth.h> |
45 | #include <sys/cpu.h> | | 45 | #include <sys/cpu.h> |
46 | | | 46 | |
47 | #include <net/if.h> | | 47 | #include <net/if.h> |
48 | #include <net/if_arp.h> | | 48 | #include <net/if_arp.h> |
| @@ -60,56 +60,80 @@ __KERNEL_RCSID(0, "$NetBSD: ipkdb_ipkdb. | | | @@ -60,56 +60,80 @@ __KERNEL_RCSID(0, "$NetBSD: ipkdb_ipkdb. |
60 | #include <ipkdb/ipkdb.h> | | 60 | #include <ipkdb/ipkdb.h> |
61 | #include <machine/ipkdb.h> | | 61 | #include <machine/ipkdb.h> |
62 | | | 62 | |
63 | int ipkdbpanic = 0; | | 63 | int ipkdbpanic = 0; |
64 | | | 64 | |
65 | #ifndef IPKDBKEY | | 65 | #ifndef IPKDBKEY |
66 | #error You must specify the IPKDBKEY option to use IPKDB. | | 66 | #error You must specify the IPKDBKEY option to use IPKDB. |
67 | #else | | 67 | #else |
68 | static char ipkdbkey[] = IPKDBKEY; | | 68 | static char ipkdbkey[] = IPKDBKEY; |
69 | #endif | | 69 | #endif |
70 | | | 70 | |
71 | static struct ipkdb_if ipkdb_if; | | 71 | static struct ipkdb_if ipkdb_if; |
72 | | | 72 | |
| | | 73 | static kauth_listener_t ipkdb_listener; |
| | | 74 | |
73 | static u_char *ipkdbaddr(u_char *, int *, void **); | | 75 | static u_char *ipkdbaddr(u_char *, int *, void **); |
74 | static void peekmem(struct ipkdb_if *, u_char *, void *, long); | | 76 | static void peekmem(struct ipkdb_if *, u_char *, void *, long); |
75 | static void pokemem(struct ipkdb_if *, u_char *, void *, long); | | 77 | static void pokemem(struct ipkdb_if *, u_char *, void *, long); |
76 | static u_int32_t getnl(void *); | | 78 | static u_int32_t getnl(void *); |
77 | static u_int getns(void *); | | 79 | static u_int getns(void *); |
78 | static void setnl(void *, u_int32_t); | | 80 | static void setnl(void *, u_int32_t); |
79 | static void setns(void *, int); | | 81 | static void setns(void *, int); |
80 | static u_short cksum(u_short, void *, int); | | 82 | static u_short cksum(u_short, void *, int); |
81 | static int assemble(struct ipkdb_if *, void *); | | 83 | static int assemble(struct ipkdb_if *, void *); |
82 | static char *inpkt(struct ipkdb_if *, char *, int); | | 84 | static char *inpkt(struct ipkdb_if *, char *, int); |
83 | static void outpkt(struct ipkdb_if *, char *, int, int, int); | | 85 | static void outpkt(struct ipkdb_if *, char *, int, int, int); |
84 | static void init(struct ipkdb_if *); | | 86 | static void init(struct ipkdb_if *); |
85 | static void *chksum(void *, int); | | 87 | static void *chksum(void *, int); |
86 | static void getpkt(struct ipkdb_if *, char *, int *); | | 88 | static void getpkt(struct ipkdb_if *, char *, int *); |
87 | static void putpkt(struct ipkdb_if *, const char *, int); | | 89 | static void putpkt(struct ipkdb_if *, const char *, int); |
88 | static int check_ipkdb(struct ipkdb_if *, struct in_addr *, char *, int); | | 90 | static int check_ipkdb(struct ipkdb_if *, struct in_addr *, char *, int); |
89 | static int connectipkdb(struct ipkdb_if *, char *, int); | | 91 | static int connectipkdb(struct ipkdb_if *, char *, int); |
90 | static int hmac_init(void); | | 92 | static int hmac_init(void); |
91 | | | 93 | |
| | | 94 | static int |
| | | 95 | ipkdb_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie, |
| | | 96 | void *arg0, void *arg1, void *arg2, void *arg3) |
| | | 97 | { |
| | | 98 | enum kauth_system_req req; |
| | | 99 | int result; |
| | | 100 | |
| | | 101 | req = (enum kauth_system_req)arg0; |
| | | 102 | result = KAUTH_RESULT_DEFER; |
| | | 103 | |
| | | 104 | if ((action != KAUTH_SYSTEM_DEBUG) || |
| | | 105 | (req != KAUTH_REQ_SYSTEM_DEBUG_IPKDB)) |
| | | 106 | return result; |
| | | 107 | |
| | | 108 | result = KAUTH_RESULT_ALLOW; |
| | | 109 | |
| | | 110 | return result; |
| | | 111 | } |
| | | 112 | |
92 | void | | 113 | void |
93 | ipkdb_init(void) | | 114 | ipkdb_init(void) |
94 | { | | 115 | { |
95 | ipkdbinit(); | | 116 | ipkdbinit(); |
96 | if ( ipkdbifinit(&ipkdb_if) < 0 | | 117 | if ( ipkdbifinit(&ipkdb_if) < 0 |
97 | || !(ipkdb_if.flags&IPKDB_MYHW) | | 118 | || !(ipkdb_if.flags&IPKDB_MYHW) |
98 | || !hmac_init()) { | | 119 | || !hmac_init()) { |
99 | /* Interface not found, drop IPKDB */ | | 120 | /* Interface not found, drop IPKDB */ |
100 | printf("IPKDB: No interface found!\n"); | | 121 | printf("IPKDB: No interface found!\n"); |
101 | boothowto &= ~RB_KDB; | | 122 | boothowto &= ~RB_KDB; |
102 | } | | 123 | } |
| | | 124 | |
| | | 125 | ipkdb_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM, |
| | | 126 | ipkdb_listener_cb, NULL); |
103 | } | | 127 | } |
104 | | | 128 | |
105 | void | | 129 | void |
106 | ipkdb_connect(int when) | | 130 | ipkdb_connect(int when) |
107 | { | | 131 | { |
108 | boothowto |= RB_KDB; | | 132 | boothowto |= RB_KDB; |
109 | if (when == 0) | | 133 | if (when == 0) |
110 | printf("waiting for remote debugger\n"); | | 134 | printf("waiting for remote debugger\n"); |
111 | ipkdb_trap(); | | 135 | ipkdb_trap(); |
112 | } | | 136 | } |
113 | | | 137 | |
114 | void | | 138 | void |
115 | ipkdb_panic(void) | | 139 | ipkdb_panic(void) |