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 | * |
| 5 | * Copyright 2000-2007 Willy Tarreau <w@1wt.eu> |
| 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 | |
| 28 | #include <types/global.h> |
| 29 | |
| 30 | #include <import/ip_tproxy.h> |
| 31 | |
| 32 | /* |
| 33 | * Checks that CTTPROXY is available and in the right version. |
| 34 | * Returns 0 if OK, -1 if wrong version, -2 if not available or other error. |
| 35 | */ |
| 36 | int check_cttproxy_version() { |
| 37 | struct in_tproxy itp1; |
| 38 | int fd; |
| 39 | |
| 40 | memset(&itp1, 0, sizeof(itp1)); |
| 41 | |
| 42 | fd = socket(AF_INET, SOCK_STREAM, 0); |
| 43 | if (fd == -1) |
| 44 | return -2; |
| 45 | |
| 46 | itp1.op = TPROXY_VERSION; |
| 47 | itp1.v.version = 0x02000000; /* CTTPROXY version 2.0 expected */ |
| 48 | |
| 49 | if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp1, sizeof(itp1)) == -1) { |
| 50 | if (errno == -EINVAL) |
| 51 | return -1; /* wrong version */ |
| 52 | else |
| 53 | return -2; /* not supported or other error */ |
| 54 | } |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | /* |
| 60 | * Local variables: |
| 61 | * c-indent-level: 8 |
| 62 | * c-basic-offset: 8 |
| 63 | * End: |
| 64 | */ |