keysock.c (181803) | keysock.c (183550) |
---|---|
1/* $FreeBSD: head/sys/netipsec/keysock.c 181803 2008-08-17 23:27:27Z bz $ */ | 1/* $FreeBSD: head/sys/netipsec/keysock.c 183550 2008-10-02 15:37:58Z zec $ */ |
2/* $KAME: keysock.c,v 1.25 2001/08/13 20:07:41 itojun Exp $ */ 3 4/*- 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 37 unchanged lines hidden (view full) --- 47#include <sys/protosw.h> 48#include <sys/signalvar.h> 49#include <sys/socket.h> 50#include <sys/socketvar.h> 51#include <sys/sysctl.h> 52#include <sys/systm.h> 53#include <sys/vimage.h> 54 | 2/* $KAME: keysock.c,v 1.25 2001/08/13 20:07:41 itojun Exp $ */ 3 4/*- 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 37 unchanged lines hidden (view full) --- 47#include <sys/protosw.h> 48#include <sys/signalvar.h> 49#include <sys/socket.h> 50#include <sys/socketvar.h> 51#include <sys/sysctl.h> 52#include <sys/systm.h> 53#include <sys/vimage.h> 54 |
55#include <net/if.h> |
|
55#include <net/raw_cb.h> 56#include <net/route.h> 57 | 56#include <net/raw_cb.h> 57#include <net/route.h> 58 |
59#include <netinet/in.h> 60 |
|
58#include <net/pfkeyv2.h> 59#include <netipsec/key.h> 60#include <netipsec/keysock.h> 61#include <netipsec/key_debug.h> | 61#include <net/pfkeyv2.h> 62#include <netipsec/key.h> 63#include <netipsec/keysock.h> 64#include <netipsec/key_debug.h> |
65#include <netipsec/ipsec.h> |
|
62 63#include <machine/stdarg.h> 64 65struct key_cb { 66 int key_count; 67 int any_count; 68}; 69static struct key_cb key_cb; --- 5 unchanged lines hidden (view full) --- 75struct pfkeystat pfkeystat; 76 77/* 78 * key_output() 79 */ 80int 81key_output(struct mbuf *m, struct socket *so) 82{ | 66 67#include <machine/stdarg.h> 68 69struct key_cb { 70 int key_count; 71 int any_count; 72}; 73static struct key_cb key_cb; --- 5 unchanged lines hidden (view full) --- 79struct pfkeystat pfkeystat; 80 81/* 82 * key_output() 83 */ 84int 85key_output(struct mbuf *m, struct socket *so) 86{ |
87 INIT_VNET_IPSEC(curvnet); |
|
83 struct sadb_msg *msg; 84 int len, error = 0; 85 86 if (m == 0) 87 panic("%s: NULL pointer was passed.\n", __func__); 88 89 V_pfkeystat.out_total++; 90 V_pfkeystat.out_bytes += m->m_pkthdr.len; --- 37 unchanged lines hidden (view full) --- 128 * send message to the socket. 129 */ 130static int 131key_sendup0(rp, m, promisc) 132 struct rawcb *rp; 133 struct mbuf *m; 134 int promisc; 135{ | 88 struct sadb_msg *msg; 89 int len, error = 0; 90 91 if (m == 0) 92 panic("%s: NULL pointer was passed.\n", __func__); 93 94 V_pfkeystat.out_total++; 95 V_pfkeystat.out_bytes += m->m_pkthdr.len; --- 37 unchanged lines hidden (view full) --- 133 * send message to the socket. 134 */ 135static int 136key_sendup0(rp, m, promisc) 137 struct rawcb *rp; 138 struct mbuf *m; 139 int promisc; 140{ |
141 INIT_VNET_IPSEC(curvnet); |
|
136 int error; 137 138 if (promisc) { 139 struct sadb_msg *pmsg; 140 141 M_PREPEND(m, sizeof(struct sadb_msg), M_DONTWAIT); 142 if (m && m->m_len < sizeof(struct sadb_msg)) 143 m = m_pullup(m, sizeof(struct sadb_msg)); --- 28 unchanged lines hidden (view full) --- 172/* XXX this interface should be obsoleted. */ 173int 174key_sendup(so, msg, len, target) 175 struct socket *so; 176 struct sadb_msg *msg; 177 u_int len; 178 int target; /*target of the resulting message*/ 179{ | 142 int error; 143 144 if (promisc) { 145 struct sadb_msg *pmsg; 146 147 M_PREPEND(m, sizeof(struct sadb_msg), M_DONTWAIT); 148 if (m && m->m_len < sizeof(struct sadb_msg)) 149 m = m_pullup(m, sizeof(struct sadb_msg)); --- 28 unchanged lines hidden (view full) --- 178/* XXX this interface should be obsoleted. */ 179int 180key_sendup(so, msg, len, target) 181 struct socket *so; 182 struct sadb_msg *msg; 183 u_int len; 184 int target; /*target of the resulting message*/ 185{ |
186 INIT_VNET_IPSEC(curvnet); |
|
180 struct mbuf *m, *n, *mprev; 181 int tlen; 182 183 /* sanity check */ 184 if (so == 0 || msg == 0) 185 panic("%s: NULL pointer was passed.\n", __func__); 186 187 KEYDEBUG(KEYDEBUG_KEY_DUMP, --- 72 unchanged lines hidden (view full) --- 260 261/* so can be NULL if target != KEY_SENDUP_ONE */ 262int 263key_sendup_mbuf(so, m, target) 264 struct socket *so; 265 struct mbuf *m; 266 int target; 267{ | 187 struct mbuf *m, *n, *mprev; 188 int tlen; 189 190 /* sanity check */ 191 if (so == 0 || msg == 0) 192 panic("%s: NULL pointer was passed.\n", __func__); 193 194 KEYDEBUG(KEYDEBUG_KEY_DUMP, --- 72 unchanged lines hidden (view full) --- 267 268/* so can be NULL if target != KEY_SENDUP_ONE */ 269int 270key_sendup_mbuf(so, m, target) 271 struct socket *so; 272 struct mbuf *m; 273 int target; 274{ |
275 INIT_VNET_NET(curvnet); 276 INIT_VNET_IPSEC(curvnet); |
|
268 struct mbuf *n; 269 struct keycb *kp; 270 int sendup; 271 struct rawcb *rp; 272 int error = 0; 273 274 if (m == NULL) 275 panic("key_sendup_mbuf: NULL pointer was passed.\n"); --- 101 unchanged lines hidden (view full) --- 377 378/* 379 * key_attach() 380 * derived from net/rtsock.c:rts_attach() 381 */ 382static int 383key_attach(struct socket *so, int proto, struct thread *td) 384{ | 277 struct mbuf *n; 278 struct keycb *kp; 279 int sendup; 280 struct rawcb *rp; 281 int error = 0; 282 283 if (m == NULL) 284 panic("key_sendup_mbuf: NULL pointer was passed.\n"); --- 101 unchanged lines hidden (view full) --- 386 387/* 388 * key_attach() 389 * derived from net/rtsock.c:rts_attach() 390 */ 391static int 392key_attach(struct socket *so, int proto, struct thread *td) 393{ |
394 INIT_VNET_IPSEC(curvnet); |
|
385 struct keycb *kp; 386 int error; 387 388 KASSERT(so->so_pcb == NULL, ("key_attach: so_pcb != NULL")); 389 390 if (td != NULL) { 391 error = priv_check(td, PRIV_NET_RAW); 392 if (error) --- 58 unchanged lines hidden (view full) --- 451 452/* 453 * key_detach() 454 * derived from net/rtsock.c:rts_detach() 455 */ 456static void 457key_detach(struct socket *so) 458{ | 395 struct keycb *kp; 396 int error; 397 398 KASSERT(so->so_pcb == NULL, ("key_attach: so_pcb != NULL")); 399 400 if (td != NULL) { 401 error = priv_check(td, PRIV_NET_RAW); 402 if (error) --- 58 unchanged lines hidden (view full) --- 461 462/* 463 * key_detach() 464 * derived from net/rtsock.c:rts_detach() 465 */ 466static void 467key_detach(struct socket *so) 468{ |
469 INIT_VNET_IPSEC(curvnet); |
|
459 struct keycb *kp = (struct keycb *)sotorawcb(so); 460 461 KASSERT(kp != NULL, ("key_detach: kp == NULL")); 462 if (kp->kp_raw.rcb_proto.sp_protocol 463 == PF_KEY) /* XXX: AF_KEY */ 464 V_key_cb.key_count--; 465 V_key_cb.any_count--; 466 --- 86 unchanged lines hidden (view full) --- 553 .pr_init = raw_init, 554 .pr_usrreqs = &key_usrreqs 555} 556}; 557 558static void 559key_init0(void) 560{ | 470 struct keycb *kp = (struct keycb *)sotorawcb(so); 471 472 KASSERT(kp != NULL, ("key_detach: kp == NULL")); 473 if (kp->kp_raw.rcb_proto.sp_protocol 474 == PF_KEY) /* XXX: AF_KEY */ 475 V_key_cb.key_count--; 476 V_key_cb.any_count--; 477 --- 86 unchanged lines hidden (view full) --- 564 .pr_init = raw_init, 565 .pr_usrreqs = &key_usrreqs 566} 567}; 568 569static void 570key_init0(void) 571{ |
572 INIT_VNET_IPSEC(curvnet); |
|
561 bzero((caddr_t)&V_key_cb, sizeof(V_key_cb)); 562 key_init(); 563} 564 565struct domain keydomain = { 566 .dom_family = PF_KEY, 567 .dom_name = "key", 568 .dom_init = key_init0, 569 .dom_protosw = keysw, 570 .dom_protoswNPROTOSW = &keysw[sizeof(keysw)/sizeof(keysw[0])] 571}; 572 573DOMAIN_SET(key); | 573 bzero((caddr_t)&V_key_cb, sizeof(V_key_cb)); 574 key_init(); 575} 576 577struct domain keydomain = { 578 .dom_family = PF_KEY, 579 .dom_name = "key", 580 .dom_init = key_init0, 581 .dom_protosw = keysw, 582 .dom_protoswNPROTOSW = &keysw[sizeof(keysw)/sizeof(keysw[0])] 583}; 584 585DOMAIN_SET(key); |