📄 klipsdebug.c
字号:
/* * control KLIPS debugging options * Copyright (C) 1996 John Ioannidis. * Copyright (C) 1998, 1999, 2000, 2001 Richard Guy Briggs. * * 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. */char klipsdebug_c_version[] = "RCSID $Id: klipsdebug.c,v 1.41 2001/06/14 19:35:14 rgb Exp $";#include <sys/types.h>#include <linux/types.h> /* new */#include <string.h>#include <errno.h>#include <stdlib.h> /* system(), strtoul() */#include <sys/stat.h> /* open() */#include <fcntl.h> /* open() */#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#include <freeswan.h>#if 0#include <linux/autoconf.h> /* CONFIG_IPSEC_PFKEYv2 */#endif/* permanently turn it on since netlink support has been disabled */ #include <signal.h> #include <pfkeyv2.h> #include <pfkey.h>#include "radij.h"#include "ipsec_encap.h"#ifndef CONFIG_IPSEC_DEBUG#define CONFIG_IPSEC_DEBUG#endif /* CONFIG_IPSEC_DEBUG */#include "ipsec_netlink.h"#include "ipsec_tunnel.h"#include "version.c"#include <stdio.h>#include <getopt.h>__u32 bigbuf[1024];char *program_name;extern unsigned int pfkey_lib_debug; /* used by libfreeswan/pfkey_v2_build */int pfkey_sock;fd_set pfkey_socks;uint32_t pfkey_seq = 0;char copyright[] ="Copyright (C) 1999 Henry Spencer, Richard Guy Briggs, D. Hugh Redelmeier,\n\ Sandy Harris, Angelos D. Keromytis, John Ioannidis.\n\\n\ This program is free software; you can redistribute it and/or modify it\n\ under the terms of the GNU General Public License as published by the\n\ Free Software Foundation; either version 2 of the License, or (at your\n\ option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.\n\\n\ This program is distributed in the hope that it will be useful, but\n\ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n\ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n\ (file COPYING in the distribution) for more details.\n";static voidusage(char * arg){ fprintf(stdout, "usage: %s {--set|--clear} {tunnel|tunnel-xmit|xform|eroute|spi|radij|esp|ah|rcv|ipcomp|verbose}\n", arg); fprintf(stdout, " %s {--all|--none}\n", arg); fprintf(stdout, " %s --help\n", arg); fprintf(stdout, " %s --version\n", arg); fprintf(stdout, " %s\n", arg); fprintf(stdout, " [ --debug ] is optional to any %s command\n", arg); fprintf(stdout, " [ --label <label> ] is optional to any %s command.\n", arg); exit(1);}static struct option const longopts[] ={ {"set", 1, 0, 's'}, {"clear", 1, 0, 'c'}, {"all", 0, 0, 'a'}, {"none", 0, 0, 'n'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {"label", 1, 0, 'l'}, {"optionsfrom", 1, 0, '+'}, {"debug", 0, 0, 'd'}, {0, 0, 0, 0}};intmain(int argc, char **argv){/* int fd; */ unsigned char action = 0; unsigned int i; int *bitfieldp; int c, previous = -1; struct encap_msghdr *em = (struct encap_msghdr *)bigbuf; int debug = 0; int error = 0; int argcount = argc; struct sadb_ext *extensions[SADB_EXT_MAX + 1]; struct sadb_msg *pfkey_msg; bitfieldp = (int *)&em->em_db_tn; program_name = argv[0]; while((c = getopt_long(argc, argv, ""/*"s:c:anhvl:+:d"*/, longopts, 0)) != EOF) { switch(c) { case 'd': debug = 1; pfkey_lib_debug = 1; argcount--; break; case 's': if(action) { fprintf(stderr, "%s: Only one of '--set', '--clear', '--all' or '--none' options permitted.\n", program_name); exit(1); } action = 's'; for (i = 0; i < (sizeof(em->Eu.Dbg)/sizeof(int)); i++) { *(bitfieldp++) = 0; } if(strcmp(optarg, "tunnel") == 0) { em->em_db_tn = -1L; } else if(strcmp(optarg, "tunnel-xmit") == 0) { em->em_db_tn = DB_TN_XMIT; } else if(strcmp(optarg, "netlink") == 0) { em->em_db_nl = -1L; } else if(strcmp(optarg, "xform") == 0) { em->em_db_xf = -1L; } else if(strcmp(optarg, "eroute") == 0) { em->em_db_er = -1L; } else if(strcmp(optarg, "spi") == 0) { em->em_db_sp = -1L; } else if(strcmp(optarg, "radij") == 0) { em->em_db_rj = -1L; } else if(strcmp(optarg, "esp") == 0) { em->em_db_es = -1L; } else if(strcmp(optarg, "ah") == 0) { em->em_db_ah = -1L; } else if(strcmp(optarg, "rcv") == 0) { em->em_db_rx = -1L; } else if(strcmp(optarg, "pfkey") == 0) { em->em_db_ky = -1L; } else if(strcmp(optarg, "comp") == 0) { em->em_db_gz = -1L; } else if(strcmp(optarg, "verbose") == 0) { em->em_db_vb = -1L; } else { usage(program_name); } em->em_db_nl |= 1 << (sizeof(em->em_db_nl) * 8 -1); break; case 'c': if(action) { fprintf(stderr, "%s: Only one of '--set', '--clear', '--all' or '--none' options permitted.\n", program_name); exit(1); } action = 'c'; for (i = 0; i < (sizeof(em->Eu.Dbg)/sizeof(int)); i++) { *(bitfieldp++) = -1; } if(strcmp(optarg, "tunnel") == 0) { em->em_db_tn = 0; } else if(strcmp(optarg, "tunnel-xmit") == 0) { em->em_db_tn = ~DB_TN_XMIT; } else if(strcmp(optarg, "netlink") == 0) { em->em_db_nl = 0; } else if(strcmp(optarg, "xform") == 0) { em->em_db_xf = 0; } else if(strcmp(optarg, "eroute") == 0) { em->em_db_er = 0; } else if(strcmp(optarg, "spi") == 0) { em->em_db_sp = 0; } else if(strcmp(optarg, "radij") == 0) { em->em_db_rj = 0; } else if(strcmp(optarg, "esp") == 0) { em->em_db_es = 0; } else if(strcmp(optarg, "ah") == 0) { em->em_db_ah = 0; } else if(strcmp(optarg, "rcv") == 0) { em->em_db_rx = 0; } else if(strcmp(optarg, "pfkey") == 0) { em->em_db_ky = 0; } else if(strcmp(optarg, "comp") == 0) { em->em_db_gz = 0; } else if(strcmp(optarg, "verbose") == 0) { em->em_db_vb = 0; } else { usage(program_name); } em->em_db_nl &= ~(1 << (sizeof(em->em_db_nl) * 8 -1)); break; case 'a': if(action) { fprintf(stderr, "%s: Only one of '--set', '--clear', '--all' or '--none' options permitted.\n", program_name); exit(1); } action = 'a'; for (i = 0; i < (sizeof(em->Eu.Dbg)/sizeof(int)) - 1; i++) { *(bitfieldp++) = -1; } *(bitfieldp++) = 0; break; case 'n': if(action) { fprintf(stderr, "%s: Only one of '--set', '--clear', '--all' or '--none' options permitted.\n", program_name); exit(1); } action = 'n'; for (i = 0; i < (sizeof(em->Eu.Dbg)/sizeof(int)); i++) { *(bitfieldp++) = 0; } break; case 'h': case '?': usage(program_name); exit(1); case 'v': fprintf(stdout, "klipsdebug (Linux FreeS/WAN %s) %s\n", freeswan_version, klipsdebug_c_version); fputs(copyright, stdout); exit(0); case 'l': program_name = malloc(strlen(argv[0]) + 10 /* update this when changing the sprintf() */ + strlen(optarg)); sprintf(program_name, "%s --label %s", argv[0], optarg); argcount -= 2; break; case '+': /* optionsfrom */ optionsfrom(optarg, &argc, &argv, optind, stderr); /* no return on error */ break; default: } previous = c; } if(argcount == 1) { system("cat /proc/net/ipsec_klipsdebug"); exit(0); } em->em_magic = EM_MAGIC; em->em_version = 0; if(action) { em->em_type = EMT_SETDEBUG; } else {#if 0 em->em_type = EMT_GETDEBUG;#else usage(program_name);#endif } em->em_msglen = EMT_SETDEBUG_FLEN; if((pfkey_sock = socket(PF_KEY, SOCK_RAW, PF_KEY_V2) ) < 0) { fprintf(stderr, "%s: Trouble openning PF_KEY family socket with error: ", program_name); switch(errno) { case ENOENT: fprintf(stderr, "device does not exist. See FreeS/WAN installation procedure.\n"); break; case EACCES: fprintf(stderr, "access denied. "); if(getuid() == 0) { fprintf(stderr, "Check permissions. Should be 600.\n"); } else { fprintf(stderr, "You must be root to open this file.\n"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -