Willy Tarreau | b38651a | 2007-03-24 17:24:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Functions for managing transparent proxying with CTTPROXY. |
| 3 | * This file should be compiled only if CTTPROXY is enabled. |
| 4 | * |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 5 | * Copyright 2000-2008 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | b38651a | 2007-03-24 17:24:39 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <errno.h> |
| 15 | #include <fcntl.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | |
| 20 | #include <sys/socket.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <common/compat.h> |
| 25 | #include <common/config.h> |
| 26 | #include <common/time.h> |
| 27 | |
Willy Tarreau | b38651a | 2007-03-24 17:24:39 +0100 | [diff] [blame] | 28 | #include <import/ip_tproxy.h> |
| 29 | |
| 30 | /* |
| 31 | * Checks that CTTPROXY is available and in the right version. |
| 32 | * Returns 0 if OK, -1 if wrong version, -2 if not available or other error. |
| 33 | */ |
| 34 | int check_cttproxy_version() { |
| 35 | struct in_tproxy itp1; |
| 36 | int fd; |
| 37 | |
| 38 | memset(&itp1, 0, sizeof(itp1)); |
| 39 | |
| 40 | fd = socket(AF_INET, SOCK_STREAM, 0); |
| 41 | if (fd == -1) |
| 42 | return -2; |
| 43 | |
| 44 | itp1.op = TPROXY_VERSION; |
| 45 | itp1.v.version = 0x02000000; /* CTTPROXY version 2.0 expected */ |
| 46 | |
| 47 | if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp1, sizeof(itp1)) == -1) { |
| 48 | if (errno == -EINVAL) |
| 49 | return -1; /* wrong version */ |
| 50 | else |
| 51 | return -2; /* not supported or other error */ |
| 52 | } |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /* |
| 58 | * Local variables: |
| 59 | * c-indent-level: 8 |
| 60 | * c-basic-offset: 8 |
| 61 | * End: |
| 62 | */ |