From 5bc92eac721d018ebd8bce5e87f57294ccb0fd54 Mon Sep 17 00:00:00 2001 From: shin Date: Thu, 30 Mar 2000 01:33:39 +0000 Subject: Bypass IPsec for traceroute invoked by root. PR: bin/17606 Submitted by: Louis Mamakos +#ifdef IPSEC +#include +#include /* XXX */ +#endif /* IPSEC */ + #include #include #ifdef HAVE_MALLOC_H @@ -322,6 +329,9 @@ void print(u_char *, int, struct sockaddr_in *); char *getaddr(u_int32_t *, char *); char *getsin(struct sockaddr_in *, char *); char *savestr(const char *); +#ifdef IPSEC +int setpolicy __P((int so, char *policy)); +#endif void send_probe(int, int); void tvsub(struct timeval *, struct timeval *); __dead void usage(void); @@ -646,6 +656,14 @@ main(int argc, char **argv) (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on, sizeof(on)); +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) + if (setpolicy(s, "in bypass") < 0) + errx(1, ipsec_strerror()); + + if (setpolicy(s, "out bypass") < 0) + errx(1, ipsec_strerror()); +#endif /* defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) */ + if (sndsock < 0) { errno = sockerrno; Fprintf(stderr, "%s: raw socket: %s\n", prog, strerror(errno)); @@ -718,6 +736,14 @@ main(int argc, char **argv) #endif } +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) + if (setpolicy(sndsock, "in bypass") < 0) + errx(1, ipsec_strerror()); + + if (setpolicy(sndsock, "out bypass") < 0) + errx(1, ipsec_strerror()); +#endif /* defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) */ + Fprintf(stderr, "%s to %s (%s)", prog, hostname, inet_ntoa(to->sin_addr)); if (source) @@ -885,6 +911,28 @@ wait_for_reply(register int sock, register struct sockaddr_in *fromp, return(cc); } +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) +int +setpolicy(so, policy) + int so; + char *policy; +{ + char *buf; + + buf = ipsec_set_policy(policy, strlen(policy)); + if (buf == NULL) { + warnx(ipsec_strerror()); + return -1; + } + (void)setsockopt(so, IPPROTO_IP, IP_IPSEC_POLICY, + buf, ipsec_get_policylen(buf)); + + free(buf); + + return 0; +} +#endif + void send_probe(int seq, int ttl) { -- cgit v1.1