1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
|
/*
* @(#) RFC2367 PF_KEYv2 Key management API message parser
* Copyright (C) 1998-2003 Richard Guy Briggs.
* Copyright (C) 2004 Michael Richardson <mcr@xelerance.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program 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 General Public License
* for more details.
*
* RCSID $Id: pfkey_v2_ext_process.c,v 1.20.2.1 2006/04/20 16:33:07 mcr Exp $
*/
/*
* Template from klips/net/ipsec/ipsec/ipsec_netlink.c.
*/
char pfkey_v2_ext_process_c_version[] = "$Id: pfkey_v2_ext_process.c,v 1.20.2.1 2006/04/20 16:33:07 mcr Exp $";
#include <linux/config.h>
#include <linux/version.h>
#include <linux/kernel.h> /* printk() */
#include "openswan/ipsec_param.h"
#ifdef MALLOC_SLAB
# include <linux/slab.h> /* kmalloc() */
#else /* MALLOC_SLAB */
# include <linux/malloc.h> /* kmalloc() */
#endif /* MALLOC_SLAB */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/interrupt.h> /* mark_bh */
#include <linux/netdevice.h> /* struct device, and other headers */
#include <linux/etherdevice.h> /* eth_type_trans */
#include <linux/ip.h> /* struct iphdr */
#include <linux/skbuff.h>
#include <openswan.h>
#include <crypto/des.h>
#ifdef SPINLOCK
# ifdef SPINLOCK_23
# include <linux/spinlock.h> /* *lock* */
# else /* SPINLOCK_23 */
# include <asm/spinlock.h> /* *lock* */
# endif /* SPINLOCK_23 */
#endif /* SPINLOCK */
#ifdef NET_21
# include <linux/in6.h>
# define ip_chk_addr inet_addr_type
# define IS_MYADDR RTN_LOCAL
#endif
#include <net/ip.h>
#ifdef NETLINK_SOCK
# include <linux/netlink.h>
#else
# include <net/netlink.h>
#endif
#include <linux/random.h> /* get_random_bytes() */
#include "openswan/radij.h"
#include "openswan/ipsec_encap.h"
#include "openswan/ipsec_sa.h"
#include "openswan/ipsec_radij.h"
#include "openswan/ipsec_xform.h"
#include "openswan/ipsec_ah.h"
#include "openswan/ipsec_esp.h"
#include "openswan/ipsec_tunnel.h"
#include "openswan/ipsec_rcv.h"
#include "openswan/ipcomp.h"
#include <pfkeyv2.h>
#include <pfkey.h>
#include "openswan/ipsec_proto.h"
#include "openswan/ipsec_alg.h"
#define SENDERR(_x) do { error = -(_x); goto errlab; } while (0)
int
pfkey_sa_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
struct sadb_sa *pfkey_sa = (struct sadb_sa *)pfkey_ext;
int error = 0;
struct ipsec_sa* ipsp;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_sa_process: .\n");
if(!extr || !extr->ips) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_sa_process: "
"extr or extr->ips is NULL, fatal\n");
SENDERR(EINVAL);
}
switch(pfkey_ext->sadb_ext_type) {
case SADB_EXT_SA:
ipsp = extr->ips;
break;
case SADB_X_EXT_SA2:
if(extr->ips2 == NULL) {
extr->ips2 = ipsec_sa_alloc(&error); /* pass error var by pointer */
}
if(extr->ips2 == NULL) {
SENDERR(-error);
}
ipsp = extr->ips2;
break;
default:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_sa_process: "
"invalid exttype=%d.\n",
pfkey_ext->sadb_ext_type);
SENDERR(EINVAL);
}
ipsp->ips_said.spi = pfkey_sa->sadb_sa_spi;
ipsp->ips_replaywin = pfkey_sa->sadb_sa_replay;
ipsp->ips_state = pfkey_sa->sadb_sa_state;
ipsp->ips_flags = pfkey_sa->sadb_sa_flags;
ipsp->ips_replaywin_lastseq = ipsp->ips_replaywin_bitmap = 0;
ipsp->ips_ref_rel = pfkey_sa->sadb_x_sa_ref;
switch(ipsp->ips_said.proto) {
case IPPROTO_AH:
ipsp->ips_authalg = pfkey_sa->sadb_sa_auth;
ipsp->ips_encalg = SADB_EALG_NONE;
break;
case IPPROTO_ESP:
ipsp->ips_authalg = pfkey_sa->sadb_sa_auth;
ipsp->ips_encalg = pfkey_sa->sadb_sa_encrypt;
ipsec_alg_sa_init(ipsp);
break;
case IPPROTO_IPIP:
ipsp->ips_authalg = AH_NONE;
ipsp->ips_encalg = ESP_NONE;
break;
#ifdef CONFIG_KLIPS_IPCOMP
case IPPROTO_COMP:
ipsp->ips_authalg = AH_NONE;
ipsp->ips_encalg = pfkey_sa->sadb_sa_encrypt;
break;
#endif /* CONFIG_KLIPS_IPCOMP */
case IPPROTO_INT:
ipsp->ips_authalg = AH_NONE;
ipsp->ips_encalg = ESP_NONE;
break;
case 0:
break;
default:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_sa_process: "
"unknown proto=%d.\n",
ipsp->ips_said.proto);
SENDERR(EINVAL);
}
errlab:
return error;
}
int
pfkey_lifetime_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
struct sadb_lifetime *pfkey_lifetime = (struct sadb_lifetime *)pfkey_ext;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_lifetime_process: .\n");
if(!extr || !extr->ips) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_lifetime_process: "
"extr or extr->ips is NULL, fatal\n");
SENDERR(EINVAL);
}
switch(pfkey_lifetime->sadb_lifetime_exttype) {
case SADB_EXT_LIFETIME_CURRENT:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_lifetime_process: "
"lifetime_current not supported yet.\n");
SENDERR(EINVAL);
break;
case SADB_EXT_LIFETIME_HARD:
ipsec_lifetime_update_hard(&extr->ips->ips_life.ipl_allocations,
pfkey_lifetime->sadb_lifetime_allocations);
ipsec_lifetime_update_hard(&extr->ips->ips_life.ipl_bytes,
pfkey_lifetime->sadb_lifetime_bytes);
ipsec_lifetime_update_hard(&extr->ips->ips_life.ipl_addtime,
pfkey_lifetime->sadb_lifetime_addtime);
ipsec_lifetime_update_hard(&extr->ips->ips_life.ipl_usetime,
pfkey_lifetime->sadb_lifetime_usetime);
break;
case SADB_EXT_LIFETIME_SOFT:
ipsec_lifetime_update_soft(&extr->ips->ips_life.ipl_allocations,
pfkey_lifetime->sadb_lifetime_allocations);
ipsec_lifetime_update_soft(&extr->ips->ips_life.ipl_bytes,
pfkey_lifetime->sadb_lifetime_bytes);
ipsec_lifetime_update_soft(&extr->ips->ips_life.ipl_addtime,
pfkey_lifetime->sadb_lifetime_addtime);
ipsec_lifetime_update_soft(&extr->ips->ips_life.ipl_usetime,
pfkey_lifetime->sadb_lifetime_usetime);
break;
default:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_lifetime_process: "
"invalid exttype=%d.\n",
pfkey_ext->sadb_ext_type);
SENDERR(EINVAL);
}
errlab:
return error;
}
int
pfkey_address_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
int saddr_len = 0;
char ipaddr_txt[ADDRTOA_BUF];
unsigned char **sap;
unsigned short * portp = 0;
struct sadb_address *pfkey_address = (struct sadb_address *)pfkey_ext;
struct sockaddr* s = (struct sockaddr*)((char*)pfkey_address + sizeof(*pfkey_address));
struct ipsec_sa* ipsp;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process:\n");
if(!extr || !extr->ips) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"extr or extr->ips is NULL, fatal\n");
SENDERR(EINVAL);
}
switch(s->sa_family) {
case AF_INET:
saddr_len = sizeof(struct sockaddr_in);
addrtoa(((struct sockaddr_in*)s)->sin_addr, 0, ipaddr_txt, sizeof(ipaddr_txt));
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found address family=%d, AF_INET, %s.\n",
s->sa_family,
ipaddr_txt);
break;
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
case AF_INET6:
saddr_len = sizeof(struct sockaddr_in6);
break;
#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
default:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"s->sa_family=%d not supported.\n",
s->sa_family);
SENDERR(EPFNOSUPPORT);
}
switch(pfkey_address->sadb_address_exttype) {
case SADB_EXT_ADDRESS_SRC:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found src address.\n");
sap = (unsigned char **)&(extr->ips->ips_addr_s);
extr->ips->ips_addr_s_size = saddr_len;
break;
case SADB_EXT_ADDRESS_DST:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found dst address.\n");
sap = (unsigned char **)&(extr->ips->ips_addr_d);
extr->ips->ips_addr_d_size = saddr_len;
break;
case SADB_EXT_ADDRESS_PROXY:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found proxy address.\n");
sap = (unsigned char **)&(extr->ips->ips_addr_p);
extr->ips->ips_addr_p_size = saddr_len;
break;
case SADB_X_EXT_ADDRESS_DST2:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found 2nd dst address.\n");
if(extr->ips2 == NULL) {
extr->ips2 = ipsec_sa_alloc(&error); /* pass error var by pointer */
}
if(extr->ips2 == NULL) {
SENDERR(-error);
}
sap = (unsigned char **)&(extr->ips2->ips_addr_d);
extr->ips2->ips_addr_d_size = saddr_len;
break;
case SADB_X_EXT_ADDRESS_SRC_FLOW:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found src flow address.\n");
if(pfkey_alloc_eroute(&(extr->eroute)) == ENOMEM) {
SENDERR(ENOMEM);
}
sap = (unsigned char **)&(extr->eroute->er_eaddr.sen_ip_src);
portp = &(extr->eroute->er_eaddr.sen_sport);
break;
case SADB_X_EXT_ADDRESS_DST_FLOW:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found dst flow address.\n");
if(pfkey_alloc_eroute(&(extr->eroute)) == ENOMEM) {
SENDERR(ENOMEM);
}
sap = (unsigned char **)&(extr->eroute->er_eaddr.sen_ip_dst);
portp = &(extr->eroute->er_eaddr.sen_dport);
break;
case SADB_X_EXT_ADDRESS_SRC_MASK:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found src mask address.\n");
if(pfkey_alloc_eroute(&(extr->eroute)) == ENOMEM) {
SENDERR(ENOMEM);
}
sap = (unsigned char **)&(extr->eroute->er_emask.sen_ip_src);
portp = &(extr->eroute->er_emask.sen_sport);
break;
case SADB_X_EXT_ADDRESS_DST_MASK:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found dst mask address.\n");
if(pfkey_alloc_eroute(&(extr->eroute)) == ENOMEM) {
SENDERR(ENOMEM);
}
sap = (unsigned char **)&(extr->eroute->er_emask.sen_ip_dst);
portp = &(extr->eroute->er_emask.sen_dport);
break;
#ifdef NAT_TRAVERSAL
case SADB_X_EXT_NAT_T_OA:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"found NAT-OA address.\n");
sap = (unsigned char **)&(extr->ips->ips_natt_oa);
extr->ips->ips_natt_oa_size = saddr_len;
break;
#endif
default:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"unrecognised ext_type=%d.\n",
pfkey_address->sadb_address_exttype);
SENDERR(EINVAL);
}
switch(pfkey_address->sadb_address_exttype) {
case SADB_EXT_ADDRESS_SRC:
case SADB_EXT_ADDRESS_DST:
case SADB_EXT_ADDRESS_PROXY:
case SADB_X_EXT_ADDRESS_DST2:
#ifdef NAT_TRAVERSAL
case SADB_X_EXT_NAT_T_OA:
#endif
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"allocating %d bytes for saddr.\n",
saddr_len);
if(!(*sap = kmalloc(saddr_len, GFP_KERNEL))) {
SENDERR(ENOMEM);
}
memcpy(*sap, s, saddr_len);
break;
default:
if(s->sa_family != AF_INET) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"s->sa_family=%d not supported.\n",
s->sa_family);
SENDERR(EPFNOSUPPORT);
}
{
unsigned long *ulsap = (unsigned long *)sap;
*ulsap = ((struct sockaddr_in*)s)->sin_addr.s_addr;
}
if (portp != 0)
*portp = ((struct sockaddr_in*)s)->sin_port;
#ifdef CONFIG_KLIPS_DEBUG
if(extr->eroute) {
char buf1[64], buf2[64];
if (debug_pfkey) {
subnettoa(extr->eroute->er_eaddr.sen_ip_src,
extr->eroute->er_emask.sen_ip_src, 0, buf1, sizeof(buf1));
subnettoa(extr->eroute->er_eaddr.sen_ip_dst,
extr->eroute->er_emask.sen_ip_dst, 0, buf2, sizeof(buf2));
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_parse: "
"extr->eroute set to %s:%d->%s:%d\n",
buf1,
ntohs(extr->eroute->er_eaddr.sen_sport),
buf2,
ntohs(extr->eroute->er_eaddr.sen_dport));
}
}
#endif /* CONFIG_KLIPS_DEBUG */
}
ipsp = extr->ips;
switch(pfkey_address->sadb_address_exttype) {
case SADB_X_EXT_ADDRESS_DST2:
ipsp = extr->ips2;
case SADB_EXT_ADDRESS_DST:
if(s->sa_family == AF_INET) {
ipsp->ips_said.dst.u.v4.sin_addr.s_addr = ((struct sockaddr_in*)(ipsp->ips_addr_d))->sin_addr.s_addr;
ipsp->ips_said.dst.u.v4.sin_family = AF_INET;
addrtoa(((struct sockaddr_in*)(ipsp->ips_addr_d))->sin_addr,
0,
ipaddr_txt,
sizeof(ipaddr_txt));
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"ips_said.dst set to %s.\n",
ipaddr_txt);
} else {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: "
"uh, ips_said.dst doesn't do address family=%d yet, said will be invalid.\n",
s->sa_family);
}
default:
break;
}
/* XXX check if port!=0 */
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_address_process: successful.\n");
errlab:
return error;
}
int
pfkey_key_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
struct sadb_key *pfkey_key = (struct sadb_key *)pfkey_ext;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_key_process: .\n");
if(!extr || !extr->ips) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_key_process: "
"extr or extr->ips is NULL, fatal\n");
SENDERR(EINVAL);
}
switch(pfkey_key->sadb_key_exttype) {
case SADB_EXT_KEY_AUTH:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_key_process: "
"allocating %d bytes for authkey.\n",
DIVUP(pfkey_key->sadb_key_bits, 8));
if(!(extr->ips->ips_key_a = kmalloc(DIVUP(pfkey_key->sadb_key_bits, 8), GFP_KERNEL))) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_key_process: "
"memory allocation error.\n");
SENDERR(ENOMEM);
}
extr->ips->ips_key_bits_a = pfkey_key->sadb_key_bits;
extr->ips->ips_key_a_size = DIVUP(pfkey_key->sadb_key_bits, 8);
memcpy(extr->ips->ips_key_a,
(char*)pfkey_key + sizeof(struct sadb_key),
extr->ips->ips_key_a_size);
break;
case SADB_EXT_KEY_ENCRYPT: /* Key(s) */
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_key_process: "
"allocating %d bytes for enckey.\n",
DIVUP(pfkey_key->sadb_key_bits, 8));
if(!(extr->ips->ips_key_e = kmalloc(DIVUP(pfkey_key->sadb_key_bits, 8), GFP_KERNEL))) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_key_process: "
"memory allocation error.\n");
SENDERR(ENOMEM);
}
extr->ips->ips_key_bits_e = pfkey_key->sadb_key_bits;
extr->ips->ips_key_e_size = DIVUP(pfkey_key->sadb_key_bits, 8);
memcpy(extr->ips->ips_key_e,
(char*)pfkey_key + sizeof(struct sadb_key),
extr->ips->ips_key_e_size);
break;
default:
SENDERR(EINVAL);
}
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_key_process: "
"success.\n");
errlab:
return error;
}
int
pfkey_ident_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
struct sadb_ident *pfkey_ident = (struct sadb_ident *)pfkey_ext;
int data_len;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_ident_process: .\n");
if(!extr || !extr->ips) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_ident_process: "
"extr or extr->ips is NULL, fatal\n");
SENDERR(EINVAL);
}
switch(pfkey_ident->sadb_ident_exttype) {
case SADB_EXT_IDENTITY_SRC:
data_len = pfkey_ident->sadb_ident_len * IPSEC_PFKEYv2_ALIGN - sizeof(struct sadb_ident);
extr->ips->ips_ident_s.type = pfkey_ident->sadb_ident_type;
extr->ips->ips_ident_s.id = pfkey_ident->sadb_ident_id;
extr->ips->ips_ident_s.len = pfkey_ident->sadb_ident_len;
if(data_len) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_ident_process: "
"allocating %d bytes for ident_s.\n",
data_len);
if(!(extr->ips->ips_ident_s.data
= kmalloc(data_len, GFP_KERNEL))) {
SENDERR(ENOMEM);
}
memcpy(extr->ips->ips_ident_s.data,
(char*)pfkey_ident + sizeof(struct sadb_ident),
data_len);
} else {
extr->ips->ips_ident_s.data = NULL;
}
break;
case SADB_EXT_IDENTITY_DST: /* Identity(ies) */
data_len = pfkey_ident->sadb_ident_len * IPSEC_PFKEYv2_ALIGN - sizeof(struct sadb_ident);
extr->ips->ips_ident_d.type = pfkey_ident->sadb_ident_type;
extr->ips->ips_ident_d.id = pfkey_ident->sadb_ident_id;
extr->ips->ips_ident_d.len = pfkey_ident->sadb_ident_len;
if(data_len) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_ident_process: "
"allocating %d bytes for ident_d.\n",
data_len);
if(!(extr->ips->ips_ident_d.data
= kmalloc(data_len, GFP_KERNEL))) {
SENDERR(ENOMEM);
}
memcpy(extr->ips->ips_ident_d.data,
(char*)pfkey_ident + sizeof(struct sadb_ident),
data_len);
} else {
extr->ips->ips_ident_d.data = NULL;
}
break;
default:
SENDERR(EINVAL);
}
errlab:
return error;
}
int
pfkey_sens_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_sens_process: "
"Sorry, I can't process exttype=%d yet.\n",
pfkey_ext->sadb_ext_type);
SENDERR(EINVAL); /* don't process these yet */
errlab:
return error;
}
int
pfkey_prop_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_prop_process: "
"Sorry, I can't process exttype=%d yet.\n",
pfkey_ext->sadb_ext_type);
SENDERR(EINVAL); /* don't process these yet */
errlab:
return error;
}
int
pfkey_supported_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_supported_process: "
"Sorry, I can't process exttype=%d yet.\n",
pfkey_ext->sadb_ext_type);
SENDERR(EINVAL); /* don't process these yet */
errlab:
return error;
}
int
pfkey_spirange_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_spirange_process: .\n");
/* errlab: */
return error;
}
int
pfkey_x_kmprivate_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_kmprivate_process: "
"Sorry, I can't process exttype=%d yet.\n",
pfkey_ext->sadb_ext_type);
SENDERR(EINVAL); /* don't process these yet */
errlab:
return error;
}
int
pfkey_x_satype_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
struct sadb_x_satype *pfkey_x_satype = (struct sadb_x_satype *)pfkey_ext;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_satype_process: .\n");
if(!extr || !extr->ips) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_satype_process: "
"extr or extr->ips is NULL, fatal\n");
SENDERR(EINVAL);
}
if(extr->ips2 == NULL) {
extr->ips2 = ipsec_sa_alloc(&error); /* pass error var by pointer */
}
if(extr->ips2 == NULL) {
SENDERR(-error);
}
if(!(extr->ips2->ips_said.proto = satype2proto(pfkey_x_satype->sadb_x_satype_satype))) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_satype_process: "
"proto lookup from satype=%d failed.\n",
pfkey_x_satype->sadb_x_satype_satype);
SENDERR(EINVAL);
}
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_satype_process: "
"protocol==%d decoded from satype==%d(%s).\n",
extr->ips2->ips_said.proto,
pfkey_x_satype->sadb_x_satype_satype,
satype2name(pfkey_x_satype->sadb_x_satype_satype));
errlab:
return error;
}
#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
int
pfkey_x_nat_t_type_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
struct sadb_x_nat_t_type *pfkey_x_nat_t_type = (struct sadb_x_nat_t_type *)pfkey_ext;
if(!pfkey_x_nat_t_type) {
printk("klips_debug:pfkey_x_nat_t_type_process: "
"null pointer passed in\n");
SENDERR(EINVAL);
}
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_nat_t_type_process: %d.\n",
pfkey_x_nat_t_type->sadb_x_nat_t_type_type);
if(!extr || !extr->ips) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_nat_t_type_process: "
"extr or extr->ips is NULL, fatal\n");
SENDERR(EINVAL);
}
switch(pfkey_x_nat_t_type->sadb_x_nat_t_type_type) {
case ESPINUDP_WITH_NON_IKE: /* with Non-IKE (older version) */
case ESPINUDP_WITH_NON_ESP: /* with Non-ESP */
extr->ips->ips_natt_type = pfkey_x_nat_t_type->sadb_x_nat_t_type_type;
break;
default:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_nat_t_type_process: "
"unknown type %d.\n",
pfkey_x_nat_t_type->sadb_x_nat_t_type_type);
SENDERR(EINVAL);
break;
}
errlab:
return error;
}
int
pfkey_x_nat_t_port_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
struct sadb_x_nat_t_port *pfkey_x_nat_t_port = (struct sadb_x_nat_t_port *)pfkey_ext;
if(!pfkey_x_nat_t_port) {
printk("klips_debug:pfkey_x_nat_t_port_process: "
"null pointer passed in\n");
SENDERR(EINVAL);
}
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_nat_t_port_process: %d/%d.\n",
pfkey_x_nat_t_port->sadb_x_nat_t_port_exttype,
pfkey_x_nat_t_port->sadb_x_nat_t_port_port);
if(!extr || !extr->ips) {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_nat_t_type_process: "
"extr or extr->ips is NULL, fatal\n");
SENDERR(EINVAL);
}
switch(pfkey_x_nat_t_port->sadb_x_nat_t_port_exttype) {
case SADB_X_EXT_NAT_T_SPORT:
extr->ips->ips_natt_sport = pfkey_x_nat_t_port->sadb_x_nat_t_port_port;
break;
case SADB_X_EXT_NAT_T_DPORT:
extr->ips->ips_natt_dport = pfkey_x_nat_t_port->sadb_x_nat_t_port_port;
break;
default:
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_nat_t_port_process: "
"unknown exttype %d.\n",
pfkey_x_nat_t_port->sadb_x_nat_t_port_exttype);
SENDERR(EINVAL);
break;
}
errlab:
return error;
}
#endif
int
pfkey_x_debug_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
{
int error = 0;
struct sadb_x_debug *pfkey_x_debug = (struct sadb_x_debug *)pfkey_ext;
if(!pfkey_x_debug) {
printk("klips_debug:pfkey_x_debug_process: "
"null pointer passed in\n");
SENDERR(EINVAL);
}
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_debug_process: .\n");
#ifdef CONFIG_KLIPS_DEBUG
if(pfkey_x_debug->sadb_x_debug_netlink >>
(sizeof(pfkey_x_debug->sadb_x_debug_netlink) * 8 - 1)) {
pfkey_x_debug->sadb_x_debug_netlink &=
~(1 << (sizeof(pfkey_x_debug->sadb_x_debug_netlink) * 8 -1));
debug_tunnel |= pfkey_x_debug->sadb_x_debug_tunnel;
debug_netlink |= pfkey_x_debug->sadb_x_debug_netlink;
debug_xform |= pfkey_x_debug->sadb_x_debug_xform;
debug_eroute |= pfkey_x_debug->sadb_x_debug_eroute;
debug_spi |= pfkey_x_debug->sadb_x_debug_spi;
debug_radij |= pfkey_x_debug->sadb_x_debug_radij;
debug_esp |= pfkey_x_debug->sadb_x_debug_esp;
debug_ah |= pfkey_x_debug->sadb_x_debug_ah;
debug_rcv |= pfkey_x_debug->sadb_x_debug_rcv;
debug_pfkey |= pfkey_x_debug->sadb_x_debug_pfkey;
#ifdef CONFIG_KLIPS_IPCOMP
sysctl_ipsec_debug_ipcomp |= pfkey_x_debug->sadb_x_debug_ipcomp;
#endif /* CONFIG_KLIPS_IPCOMP */
sysctl_ipsec_debug_verbose |= pfkey_x_debug->sadb_x_debug_verbose;
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_debug_process: "
"set\n");
} else {
KLIPS_PRINT(debug_pfkey,
"klips_debug:pfkey_x_debug_process: "
"unset\n");
debug_tunnel &= pfkey_x_debug->sadb_x_debug_tunnel;
debug_netlink &= pfkey_x_debug->sadb_x_debug_netlink;
debug_xform &= pfkey_x_debug->sadb_x_debug_xform;
debug_eroute &= pfkey_x_debug->sadb_x_debug_eroute;
debug_spi &= pfkey_x_debug->sadb_x_debug_spi;
debug_radij &= pfkey_x_debug->sadb_x_debug_radij;
debug_esp &= pfkey_x_debug->sadb_x_debug_esp;
debug_ah &= pfkey_x_debug->sadb_x_debug_ah;
debug_rcv &= pfkey_x_debug->sadb_x_debug_rcv;
debug_pfkey &= pfkey_x_debug->sadb_x_debug_pfkey;
#ifdef CONFIG_KLIPS_IPCOMP
sysctl_ipsec_debug_ipcomp &= pfkey_x_debug->sadb_x_debug_ipcomp;
#endif /* CONFIG_KLIPS_IPCOMP */
sysctl_ipsec_debug_verbose &= pfkey_x_debug->sadb_x_debug_verbose;
}
#else /* CONFIG_KLIPS_DEBUG */
printk("klips_debug:pfkey_x_debug_process: "
"debugging not enabled\n");
SENDERR(EINVAL);
#endif /* CONFIG_KLIPS_DEBUG */
errlab:
return error;
}
/*
* $Log: pfkey_v2_ext_process.c,v $
* Revision 1.20.2.1 2006/04/20 16:33:07 mcr
* remove all of CONFIG_KLIPS_ALG --- one can no longer build without it.
* Fix in-kernel module compilation. Sub-makefiles do not work.
*
* Revision 1.20 2005/04/29 05:10:22 mcr
* removed from extraenous includes to make unit testing easier.
*
* Revision 1.19 2004/12/04 07:14:18 mcr
* resolution to gcc3-ism was wrong. fixed to assign correct
* variable.
*
* Revision 1.18 2004/12/03 21:25:57 mcr
* compile time fixes for running on 2.6.
* still experimental.
*
* Revision 1.17 2004/08/21 00:45:04 mcr
* CONFIG_KLIPS_NAT was wrong, also need to include udp.h.
*
* Revision 1.16 2004/07/10 19:11:18 mcr
* CONFIG_IPSEC -> CONFIG_KLIPS.
*
* Revision 1.15 2004/04/06 02:49:26 mcr
* pullup of algo code from alg-branch.
*
* Revision 1.14 2004/02/03 03:13:59 mcr
* no longer #ifdef out NON_ESP mode. That was a mistake.
*
* Revision 1.13 2003/12/15 18:13:12 mcr
* when compiling with NAT traversal, don't assume that the
* kernel has been patched, unless CONFIG_IPSEC_NAT_NON_ESP
* is set.
*
* Revision 1.12.2.1 2003/12/22 15:25:52 jjo
* Merged algo-0.8.1-rc11-test1 into alg-branch
*
* Revision 1.12 2003/12/10 01:14:27 mcr
* NAT-traversal patches to KLIPS.
*
* Revision 1.11 2003/10/31 02:27:55 mcr
* pulled up port-selector patches and sa_id elimination.
*
* Revision 1.10.4.2 2003/10/29 01:30:41 mcr
* elimited "struct sa_id".
*
* Revision 1.10.4.1 2003/09/21 13:59:56 mcr
* pre-liminary X.509 patch - does not yet pass tests.
*
* Revision 1.10 2003/02/06 01:51:41 rgb
* Removed no longer relevant comment
*
* Revision 1.9 2003/01/30 02:32:44 rgb
*
* Transmit error code through to caller from callee for better diagnosis of problems.
*
* Revision 1.8 2002/12/13 22:42:22 mcr
* restored sa_ref code
*
* Revision 1.7 2002/12/13 22:40:48 mcr
* temporarily removed sadb_x_sa_ref reference for 2.xx
*
* Revision 1.6 2002/10/05 05:02:58 dhr
*
* C labels go on statements
*
* Revision 1.5 2002/09/20 15:41:08 rgb
* Switch from pfkey_alloc_ipsec_sa() to ipsec_sa_alloc().
* Added sadb_x_sa_ref to struct sadb_sa.
*
* Revision 1.4 2002/09/20 05:02:02 rgb
* Added memory allocation debugging.
*
* Revision 1.3 2002/07/24 18:44:54 rgb
* Type fiddling to tame ia64 compiler.
*
* Revision 1.2 2002/05/27 18:55:03 rgb
* Remove final vistiges of tdb references via IPSEC_KLIPS1_COMPAT.
*
* Revision 1.1 2002/05/14 02:33:51 rgb
* Moved all the extension processing functions to pfkey_v2_ext_process.c.
*
*
* Local variables:
* c-file-style: "linux"
* End:
*
*/
|