blob: eaa47342b21178a18790de81b05b11d6326604ee [file] [log] [blame]
Willy Tarreaub38651a2007-03-24 17:24:39 +01001/*
2 * Functions for managing transparent proxying with CTTPROXY.
3 * This file should be compiled only if CTTPROXY is enabled.
4 *
Willy Tarreauec6c5df2008-07-15 00:22:45 +02005 * Copyright 2000-2008 Willy Tarreau <w@1wt.eu>
Willy Tarreaub38651a2007-03-24 17:24:39 +01006 *
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>
Willy Tarreau71e451c2012-10-05 22:18:07 +020019#include <unistd.h>
Willy Tarreaub38651a2007-03-24 17:24:39 +010020
21#include <sys/socket.h>
22#include <sys/stat.h>
23#include <sys/types.h>
24
25#include <common/compat.h>
26#include <common/config.h>
27#include <common/time.h>
28
Willy Tarreaub38651a2007-03-24 17:24:39 +010029#include <import/ip_tproxy.h>
30
31/*
32 * Checks that CTTPROXY is available and in the right version.
33 * Returns 0 if OK, -1 if wrong version, -2 if not available or other error.
34 */
35int check_cttproxy_version() {
36 struct in_tproxy itp1;
Delta Yehaf01c7c2010-05-03 22:08:33 +080037 int fd, ret;
Willy Tarreaub38651a2007-03-24 17:24:39 +010038
39 memset(&itp1, 0, sizeof(itp1));
40
41 fd = socket(AF_INET, SOCK_STREAM, 0);
42 if (fd == -1)
43 return -2;
44
45 itp1.op = TPROXY_VERSION;
46 itp1.v.version = 0x02000000; /* CTTPROXY version 2.0 expected */
Delta Yehaf01c7c2010-05-03 22:08:33 +080047
48 ret = 0;
Willy Tarreaub38651a2007-03-24 17:24:39 +010049 if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp1, sizeof(itp1)) == -1) {
50 if (errno == -EINVAL)
Delta Yehaf01c7c2010-05-03 22:08:33 +080051 ret = -1; /* wrong version */
Willy Tarreaub38651a2007-03-24 17:24:39 +010052 else
Delta Yehaf01c7c2010-05-03 22:08:33 +080053 ret = -2; /* not supported or other error */
Willy Tarreaub38651a2007-03-24 17:24:39 +010054 }
Delta Yehaf01c7c2010-05-03 22:08:33 +080055 close(fd);
56 return ret;
Willy Tarreaub38651a2007-03-24 17:24:39 +010057}
58
59
60/*
61 * Local variables:
62 * c-indent-level: 8
63 * c-basic-offset: 8
64 * End:
65 */