Skip to content
Snippets Groups Projects
Commit 813bddc0 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Remove haproxy clone

parent 3735ad51
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 10970 deletions
*.o
*/.svn
*~
.flxdisk*
.flxpkg
.flxstatus*
.svn
haproxy
src/*.o
*.rej
*.orig
*.log*
*.trace*
haproxy-*
!doc/haproxy-*.txt
!src/*.c
make-*
dlmalloc.c
00*.patch
*.service
*.bak
.nfs*
contrib/base64/base64rev
contrib/halog/halog
contrib/ip6range/ip6range
contrib/iprange/iprange
tests/test_hashes
/*.cfg
/*.conf
/*.diff
/*.patch
/*.c
/*.o
/*.so
/*.txt
/*.TXT
/*.txt.*
/*.prof
/*.gprof
/*.prof.*
/*.gprof.*
/*.tar
/*.tar.gz
/*.tgz
/*.mbox
/*.sh
/bug*
/TAGS
# Below we forbid everything and only allow what we know, that's much easier
# than blocking about 500 different test files and bug report outputs.
/.*
/*
!/.gitignore
!/CHANGELOG
!/LICENSE
!/Makefile
!/README
!/CONTRIBUTING
!/MAINTAINERS
!/ROADMAP
!/SUBVERS
!/VERDATE
!/VERSION
!/contrib
!/doc
!/ebtree
!/examples
!/include
!/src
!/tests
!/debian
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
HAPROXY's license - 2006/06/15
Historically, haproxy has been covered by GPL version 2. However, an issue
appeared in GPL which will prevent external non-GPL code from being built
using the headers provided with haproxy. My long-term goal is to build a core
system able to load external modules to support specific application protocols.
Since some protocols are found in rare environments (finance, industry, ...),
some of them might be accessible only after signing an NDA. Enforcing GPL on
such modules would only prevent them from ever being implemented, while not
providing anything useful to ordinary users.
For this reason, I *want* to be able to support binary only external modules
when needed, with a GPL core and GPL modules for standard protocols, so that
people fixing bugs don't keep them secretly to try to stay over competition.
The solution was then to apply the LGPL license to the exportable include
files, while keeping the GPL for all the rest. This way, it still is mandatory
to redistribute modified code under customer request, but at the same time, it
is expressly permitted to write, compile, link and load non-GPL code using the
LGPL header files and not to distribute them if it causes a legal problem.
Of course, users are strongly encouraged to continue the work under GPL as long
as possible, since this license has allowed useful enhancements, contributions
and fixes from talented people around the world.
Due to the incompatibility between the GPL and the OpenSSL licence, you must
apply the GPL/LGPL licence with the following exception:
This program is released under the GPL with the additional exemption that
compiling, linking, and/or using OpenSSL is allowed.
The text of the licenses lies in the "doc" directory. All the files provided in
this package are covered by the GPL unless expressly stated otherwise in them.
Every patch or contribution provided by external people will by default comply
with the license of the files it affects, or be rejected.
Willy Tarreau - w@1wt.eu
This file contains a list of people who are responsible for certain parts of
the HAProxy project and who have authority on them. This means that these
people have to be consulted before doing any change in the parts they maintain,
including when fixing bugs. These persons are allowed to reject any change on
the parts they maintain, and in parallel they try their best to ensure these
parts work well. Similarly, any change to these parts not being validated by
them will be rejected.
The best way to deal with such subsystems when sending patches is to send the
patches to the mailing list and to CC these people. When no maintainer is
listed for a subsystem, you can simply send your changes the usual way, and it
is also a sign that if you want to strengthen your skills on certain parts you
can become yourself a maintainer of the parts you care a lot about.
Please do not ask them to troubleshoot your bugs, it's not their job eventhough
they may occasionally help as time permits.
List of maintainers
-------------------
Lua
Maintainer: Thierry Fournier <tfournier@arpalert.org>
Files: src/hlua.c, include/*/hlua.h
Maps and pattern matching
Maintainer: Thierry Fournier <tfournier@arpalert.org>
Files: src/maps.c, src/pattern.c, include/*/maps.h, include/*/pattern.h
DNS
Maintainer: Baptiste Assmann <bedis9@gmail.com>
Files: src/dns.c, include/*/dns.h
SSL
Maintainer: Emeric Brun <ebrun@haproxy.com>
Files: src/ssl_sock.c, include/*/ssl_sock.h
Peers
Maintainer: Emeric Brun <ebrun@haproxy.com>
Files: src/peers.c, include/*/peers.h
Doc to HTML converter (dconv)
Maintainer: Cyril Bonté <cyril.bonte@free.fr>
Files: doc/*.txt
Note: ask Cyril before changing any doc's format or structure.
Health checks
Files: src/checks.c, include/*/checks.h
Maintainers: Simon Horman for external-check, Baptiste Assmann for tcp-check
Note: health checks are fragile and have been broken many times, so please
consult the relevant maintainers if you want to change these specific
parts.
Mailers
Maintainer: Simon Horman <horms@verge.net.au>
Files: src/mailers.c, include/*/mailers.h
DeviceAtlas device identification
Maintainer: David Carlier <dcarlier@afilias.info>
Files: src/da.c, include/*/da.h
51Degrees device identification
Maintainer: Ben Shillito <ben@51degrees.com>
Files: src/51d.c
This diff is collapsed.
This diff is collapsed.
Medium-long term roadmap - 2015/10/13
Legend: '+' = done, '-' = todo, '*' = done except doc
1.7 or later :
- return-html code xxx [ file "xxx" | text "xxx" ] if <acl>
- return-raw [ file "xxx" | text "xxx" ] if <acl>
- add the ability to only dump response errors to more easily detect
anomalies without being polluted with attacks in requests.
- have multi-criteria analysers which subscribe to req flags, rsp flags, and
stream interface changes. This would result in a single analyser to wait
for the end of data transfer in HTTP.
- support for time-ordered priority queues with ability to add an offset
based on request matching. Each session will have one ebtree node to be
attached to whatever queue the session is waiting in.
- add a flag in logs to indicate keep-alive requests ?
- make it possible to condition a timeout on an ACL (dynamic timeouts)
- forwardfor/originalto except with IPv6
- remove lots of remaining Alert() calls or ensure that they forward to
send_log() after the fork.
- tcp-request session
- tcp-request session expect-proxy {L4|L5} if ...
- wait on resource (time, mem, CPU, socket, server's conn, server's rate, ...)
- bandwidth limits
- buddy servers to build defined lists of failovers. Detect loops during
the config check.
server XXX buddy YYY
server YYY # may replace XXX when XXX fails
- spare servers : servers which are used in LB only when a minimum farm
weight threshold is not satisfied anymore. Useful for inter-site LB with
local pref by default.
- add support for event-triggered epoll, and maybe change all events handling
to pass through an event cache to handle temporarily disabled events.
- evaluate the changes required for multi-process+shared mem or multi-thread
+thread-local+fast locking.
- ability to decide whether to drain or kill sessions when putting a server
to maintenance mode => requires a per-server session list and the change
above.
Old, maybe obsolete points :
- clarify licence by adding a 'MODULE_LICENCE("GPL")' or something equivalent.
- 3 memory models : failsafe (prealloc), normal (current), optimal (alloc on
demand)
- implement support for event-triggerred epoll()
- verify if it would be worth implementing an epoll_ctl_batch() for Linux
- option minservers XXX : activates some spare servers when active servers
are insufficient
- initcwnd parameter for bind sockets : needed in kernel first
- have a callback function which would be called after a server is selected,
for header post-processing. That would be mainly used to remove then add
the server's name or cookie in a header so that the server knows it.
Unsorted :
- outgoing log load-balancing (round-robin or hash among multiple servers)
- internal socket for "server XXX frontend:name"
- HTTP/2.0
- XML inspection (content-switching for SOAP requests)
- random cookie generator
- fastcgi to servers
- hot config reload
- RAM-based cache for small files
- RHI - BGP
- telnet/SSH cli
- dynamic memory allocation
- dynamic weights based on check response headers and traffic response time
- various kernel-level acceleration (multi-accept, ssplice, epoll2...)
-$Format:%h$
$Format:%ci$
2016/06/26
1.6.6
/*
* base64rev generator
*
* Copyright 2009-2010 Krzysztof Piotr Oledzki <ole@ans.pl>
*
* 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.
*
*/
#include <stdio.h>
const char base64tab[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char base64rev[128];
#define base '#' /* arbitrary chosen base value */
#define B64MAX 64
#define B64PADV B64MAX
int main() {
char *p, c;
int i, min = 255, max = 0;
for (i = 0; i < sizeof(base64rev); i++)
base64rev[i] = base;
for (i = 0; i < B64MAX; i++) {
c = base64tab[i];
if (min > c)
min = c;
if (max < c)
max = c;
}
for (i = 0; i < B64MAX; i++) {
c = base64tab[i];
if (base+i+1 > 127) {
printf("Wrong base value @%d\n", i);
return 1;
}
base64rev[c - min] = base+i+1;
}
base64rev['=' - min] = base + B64PADV;
base64rev[max - min + 1] = '\0';
printf("#define B64BASE '%c'\n", base);
printf("#define B64CMIN '%c'\n", min);
printf("#define B64CMAX '%c'\n", max);
printf("#define B64PADV %u\n", B64PADV);
p = base64rev;
printf("const char base64rev[]=\"");
for (p = base64rev; *p; p++) {
if (*p == '\\')
printf("\\%c", *p);
else
printf("%c", *p);
}
printf("\"\n");
return 0;
}
EBTREE_DIR = ../../ebtree
INCLUDE = -I../../include -I$(EBTREE_DIR)
CC = gcc
# note: it is recommended to also add -fomit-frame-pointer on i386
OPTIMIZE = -O3
# most recent glibc provide platform-specific optimizations that make
# memchr faster than the generic C implementation (eg: SSE and prefetch
# on x86_64). Try with an without. In general, on x86_64 it's better to
# use memchr using the define below.
# DEFINE = -DUSE_MEMCHR
DEFINE =
OBJS = halog
halog: halog.c fgets2.c
$(CC) $(OPTIMIZE) $(DEFINE) -o $@ $(INCLUDE) $(EBTREE_DIR)/ebtree.c $(EBTREE_DIR)/eb32tree.c $(EBTREE_DIR)/eb64tree.c $(EBTREE_DIR)/ebmbtree.c $(EBTREE_DIR)/ebsttree.c $(EBTREE_DIR)/ebistree.c $(EBTREE_DIR)/ebimtree.c $^
clean:
rm -f $(OBJS) *.[oas]
/*
* fast fgets() replacement for log parsing
*
* Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* This function manages its own buffer and returns a pointer to that buffer
* in order to avoid expensive memory copies. It also checks for line breaks
* 32 or 64 bits at a time. It could be improved a lot using mmap() but we
* would not be allowed to replace trailing \n with zeroes and we would be
* limited to small log files on 32-bit machines.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#ifndef FGETS2_BUFSIZE
#define FGETS2_BUFSIZE (256*1024)
#endif
/* return non-zero if the integer contains at least one zero byte */
static inline unsigned int has_zero32(unsigned int x)
{
unsigned int y;
/* Principle: we want to perform 4 tests on one 32-bit int at once. For
* this, we have to simulate an SIMD instruction which we don't have by
* default. The principle is that a zero byte is the only one which
* will cause a 1 to appear on the upper bit of a byte/word/etc... when
* we subtract 1. So we can detect a zero byte if a one appears at any
* of the bits 7, 15, 23 or 31 where it was not. It takes only one
* instruction to test for the presence of any of these bits, but it is
* still complex to check for their initial absence. Thus, we'll
* proceed differently : we first save and clear only those bits, then
* we check in the final result if one of them is present and was not.
* The order of operations below is important to save registers and
* tests. The result is used as a boolean, so the last test must apply
* on the constant so that it can efficiently be inlined.
*/
#if defined(__i386__)
/* gcc on x86 loves copying registers over and over even on code that
* simple, so let's do it by hand to prevent it from doing so :-(
*/
asm("lea -0x01010101(%0),%1\n"
"not %0\n"
"and %1,%0\n"
: "=a" (x), "=r"(y)
: "0" (x)
);
return x & 0x80808080;
#else
y = x - 0x01010101; /* generate a carry */
x = ~x & y; /* clear the bits that were already set */
return x & 0x80808080;
#endif
}
/* return non-zero if the argument contains at least one zero byte. See principle above. */
static inline unsigned long long has_zero64(unsigned long long x)
{
unsigned long long y;
y = x - 0x0101010101010101ULL; /* generate a carry */
y &= ~x; /* clear the bits that were already set */
return y & 0x8080808080808080ULL;
}
static inline unsigned long has_zero(unsigned long x)
{
return (sizeof(x) == 8) ? has_zero64(x) : has_zero32(x);
}
/* find a '\n' between <next> and <end>. Warning: may read slightly past <end>.
* If no '\n' is found, <end> is returned.
*/
static char *find_lf(char *next, char *end)
{
#if defined USE_MEMCHR
/* some recent libc use platform-specific optimizations to provide more
* efficient byte search than below (eg: glibc 2.11 on x86_64).
*/
next = memchr(next, '\n', end - next);
if (!next)
next = end;
#else
if (sizeof(long) == 4) { /* 32-bit system */
/* this is a speed-up, we read 32 bits at once and check for an
* LF character there. We stop if found then continue one at a
* time.
*/
while (next < end && (((unsigned long)next) & 3) && *next != '\n')
next++;
/* Now next is multiple of 4 or equal to end. We know we can safely
* read up to 32 bytes past end if needed because they're allocated.
*/
while (next < end) {
if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A))
break;
next += 4;
if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A))
break;
next += 4;
if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A))
break;
next += 4;
if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A))
break;
next += 4;
if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A))
break;
next += 4;
if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A))
break;
next += 4;
if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A))
break;
next += 4;
if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A))
break;
next += 4;
}
}
else { /* 64-bit system */
/* this is a speed-up, we read 64 bits at once and check for an
* LF character there. We stop if found then continue one at a
* time.
*/
if (next <= end) {
/* max 3 bytes tested here */
while ((((unsigned long)next) & 3) && *next != '\n')
next++;
/* maybe we have can skip 4 more bytes */
if ((((unsigned long)next) & 4) && !has_zero32(*(unsigned int *)next ^ 0x0A0A0A0AU))
next += 4;
}
/* now next is multiple of 8 or equal to end */
while (next <= (end-68)) {
if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL))
break;
next += 8;
if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL))
break;
next += 8;
if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL))
break;
next += 8;
if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL))
break;
next += 8;
if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL))
break;
next += 8;
if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL))
break;
next += 8;
if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL))
break;
next += 8;
if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL))
break;
next += 8;
}
/* maybe we can skip 4 more bytes */
if (!has_zero32(*(unsigned int *)next ^ 0x0A0A0A0AU))
next += 4;
}
/* We finish if needed : if <next> is below <end>, it means we
* found an LF in one of the 4 following bytes.
*/
while (next < end) {
if (*next == '\n')
break;
next++;
}
#endif
return next;
}
const char *fgets2(FILE *stream)
{
static char buffer[FGETS2_BUFSIZE + 68]; /* Note: +32 is enough on 32-bit systems */
static char *end = buffer;
static char *line = buffer;
char *next;
int ret;
next = line;
while (1) {
next = find_lf(next, end);
if (next < end) {
const char *start = line;
*next = '\0';
line = next + 1;
return start;
}
/* we found an incomplete line. First, let's move the
* remaining part of the buffer to the beginning, then
* try to complete the buffer with a new read. We can't
* rely on <next> anymore because it went past <end>.
*/
if (line > buffer) {
if (end != line)
memmove(buffer, line, end - line);
end = buffer + (end - line);
next = end;
line = buffer;
} else {
if (end == buffer + FGETS2_BUFSIZE)
return NULL;
}
ret = read(fileno(stream), end, buffer + FGETS2_BUFSIZE - end);
if (ret <= 0) {
if (end == line)
return NULL;
*end = '\0';
end = line; /* ensure we stop next time */
return line;
}
end += ret;
*end = '\n'; /* make parser stop ASAP */
/* search for '\n' again */
}
}
#ifdef BENCHMARK
int main() {
const char *p;
unsigned int lines = 0;
while ((p=fgets2(stdin)))
lines++;
printf("lines=%d\n", lines);
return 0;
}
#endif
This diff is collapsed.
CC = gcc
OPTIMIZE = -O3
LDFLAGS = -s
OBJS = ip6range
all: $(OBJS)
%: %.c
$(CC) $(LDFLAGS) $(OPTIMIZE) -o $@ $^
clean:
rm -f $(OBJS) *.o *.a *~
/*
* network range to IP+mask converter
*
* Copyright 2011-2012 Willy Tarreau <w@1wt.eu>
*
* This program reads lines starting by two IP addresses and outputs them with
* the two IP addresses replaced by a netmask covering the range between these
* IPs (inclusive). When multiple ranges are needed, as many lines are emitted.
* The IP addresses may be delimited by spaces, tabs or commas. Quotes are
* stripped, and lines beginning with a sharp character ('#') are ignored. The
* IP addresses may be either in the dotted format or represented as a 32-bit
* integer value in network byte order.
*
* 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.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 1024
static inline void in6_bswap(struct in6_addr *a)
{
a->in6_u.u6_addr32[0] = ntohl(a->in6_u.u6_addr32[0]);
a->in6_u.u6_addr32[1] = ntohl(a->in6_u.u6_addr32[1]);
a->in6_u.u6_addr32[2] = ntohl(a->in6_u.u6_addr32[2]);
a->in6_u.u6_addr32[3] = ntohl(a->in6_u.u6_addr32[3]);
}
/* returns a string version of an IPv6 address in host order */
static const char *get_ipv6_addr(struct in6_addr *addr)
{
struct in6_addr a;
static char out[INET6_ADDRSTRLEN + 1];
memcpy(&a, addr, sizeof(struct in6_addr));
in6_bswap(&a);
return inet_ntop(AF_INET6, &a, out, INET6_ADDRSTRLEN + 1);
}
static const char *get_addr(struct in6_addr *addr)
{
static char out[50];
snprintf(out, 50, "%08x:%08x:%08x:%08x",
addr->in6_u.u6_addr32[0],
addr->in6_u.u6_addr32[1],
addr->in6_u.u6_addr32[2],
addr->in6_u.u6_addr32[3]);
return out;
}
/* a <= b */
static inline int a_le_b(struct in6_addr *a, struct in6_addr *b)
{
if (a->in6_u.u6_addr32[0] < b->in6_u.u6_addr32[0]) return 1;
if (a->in6_u.u6_addr32[0] > b->in6_u.u6_addr32[0]) return 0;
if (a->in6_u.u6_addr32[1] < b->in6_u.u6_addr32[1]) return 1;
if (a->in6_u.u6_addr32[1] > b->in6_u.u6_addr32[1]) return 0;
if (a->in6_u.u6_addr32[2] < b->in6_u.u6_addr32[2]) return 1;
if (a->in6_u.u6_addr32[2] > b->in6_u.u6_addr32[2]) return 0;
if (a->in6_u.u6_addr32[3] < b->in6_u.u6_addr32[3]) return 1;
if (a->in6_u.u6_addr32[3] > b->in6_u.u6_addr32[3]) return 0;
return 1;
}
/* a == b */
static inline int a_eq_b(struct in6_addr *a, struct in6_addr *b)
{
if (a->in6_u.u6_addr32[0] != b->in6_u.u6_addr32[0]) return 0;
if (a->in6_u.u6_addr32[1] != b->in6_u.u6_addr32[1]) return 0;
if (a->in6_u.u6_addr32[2] != b->in6_u.u6_addr32[2]) return 0;
if (a->in6_u.u6_addr32[3] != b->in6_u.u6_addr32[3]) return 0;
return 1;
}
/* a > b */
static inline int a_gt_b(struct in6_addr *a, struct in6_addr *b)
{
if (a->in6_u.u6_addr32[0] > b->in6_u.u6_addr32[0]) return 1;
if (a->in6_u.u6_addr32[0] < b->in6_u.u6_addr32[0]) return 0;
if (a->in6_u.u6_addr32[1] > b->in6_u.u6_addr32[1]) return 1;
if (a->in6_u.u6_addr32[1] < b->in6_u.u6_addr32[1]) return 0;
if (a->in6_u.u6_addr32[2] > b->in6_u.u6_addr32[2]) return 1;
if (a->in6_u.u6_addr32[2] < b->in6_u.u6_addr32[2]) return 0;
if (a->in6_u.u6_addr32[3] > b->in6_u.u6_addr32[3]) return 1;
if (a->in6_u.u6_addr32[3] < b->in6_u.u6_addr32[3]) return 0;
return 0;
}
/* ( 1 << m ) - 1 -> r */
static inline struct in6_addr *hmask(unsigned int b, struct in6_addr *r)
{
if (b < 32) {
r->in6_u.u6_addr32[3] = (1 << b) - 1;
r->in6_u.u6_addr32[2] = 0;
r->in6_u.u6_addr32[1] = 0;
r->in6_u.u6_addr32[0] = 0;
}
else if (b < 64) {
r->in6_u.u6_addr32[3] = 0xffffffff;
r->in6_u.u6_addr32[2] = (1 << (b - 32)) - 1;
r->in6_u.u6_addr32[1] = 0;
r->in6_u.u6_addr32[0] = 0;
}
else if (b < 96) {
r->in6_u.u6_addr32[3] = 0xffffffff;
r->in6_u.u6_addr32[2] = 0xffffffff;
r->in6_u.u6_addr32[1] = (1 << (b - 64)) - 1;
r->in6_u.u6_addr32[0] = 0;
}
else if (b < 128) {
r->in6_u.u6_addr32[3] = 0xffffffff;
r->in6_u.u6_addr32[2] = 0xffffffff;
r->in6_u.u6_addr32[1] = 0xffffffff;
r->in6_u.u6_addr32[0] = (1 << (b - 96)) - 1;
}
else {
r->in6_u.u6_addr32[3] = 0xffffffff;
r->in6_u.u6_addr32[2] = 0xffffffff;
r->in6_u.u6_addr32[1] = 0xffffffff;
r->in6_u.u6_addr32[0] = 0xffffffff;
}
return r;
}
/* 1 << b -> r */
static inline struct in6_addr *one_ls_b(unsigned int b, struct in6_addr *r)
{
if (b < 32) {
r->in6_u.u6_addr32[3] = 1 << b;
r->in6_u.u6_addr32[2] = 0;
r->in6_u.u6_addr32[1] = 0;
r->in6_u.u6_addr32[0] = 0;
}
else if (b < 64) {
r->in6_u.u6_addr32[3] = 0;
r->in6_u.u6_addr32[2] = 1 << (b - 32);
r->in6_u.u6_addr32[1] = 0;
r->in6_u.u6_addr32[0] = 0;
}
else if (b < 96) {
r->in6_u.u6_addr32[3] = 0;
r->in6_u.u6_addr32[2] = 0;
r->in6_u.u6_addr32[1] = 1 << (b - 64);
r->in6_u.u6_addr32[0] = 0;
}
else if (b < 128) {
r->in6_u.u6_addr32[3] = 0;
r->in6_u.u6_addr32[2] = 0;
r->in6_u.u6_addr32[1] = 0;
r->in6_u.u6_addr32[0] = 1 << (b - 96);
}
else {
r->in6_u.u6_addr32[3] = 0;
r->in6_u.u6_addr32[2] = 0;
r->in6_u.u6_addr32[1] = 0;
r->in6_u.u6_addr32[0] = 0;
}
return r;
}
/* a + b -> r */
static inline struct in6_addr *a_plus_b(struct in6_addr *a, struct in6_addr *b, struct in6_addr *r)
{
unsigned long long int c = 0;
int i;
for (i=3; i>=0; i--) {
c = (unsigned long long int)a->in6_u.u6_addr32[i] +
(unsigned long long int)b->in6_u.u6_addr32[i] + c;
r->in6_u.u6_addr32[i] = c;
c >>= 32;
}
return r;
}
/* a - b -> r */
static inline struct in6_addr *a_minus_b(struct in6_addr *a, struct in6_addr *b, struct in6_addr *r)
{
signed long long int c = 0;
signed long long int d;
int i;
/* Check sign. Return 0xff..ff (-1) if the result is less than 0. */
if (a_gt_b(b, a)) {
r->in6_u.u6_addr32[3] = 0xffffffff;
r->in6_u.u6_addr32[2] = 0xffffffff;
r->in6_u.u6_addr32[1] = 0xffffffff;
r->in6_u.u6_addr32[0] = 0xffffffff;
return r;
}
for (i=3; i>=0; i--) {
d = (unsigned long long int)b->in6_u.u6_addr32[i] + c;
c = (unsigned long long int)a->in6_u.u6_addr32[i];
if (c < d)
c += 0x100000000ULL;
c -= d;
r->in6_u.u6_addr32[i] = c;
c >>= 32;
}
return r;
}
/* a & b -> r */
static inline struct in6_addr *a_and_b(struct in6_addr *a, struct in6_addr *b, struct in6_addr *r)
{
r->in6_u.u6_addr32[0] = a->in6_u.u6_addr32[0] & b->in6_u.u6_addr32[0];
r->in6_u.u6_addr32[1] = a->in6_u.u6_addr32[1] & b->in6_u.u6_addr32[1];
r->in6_u.u6_addr32[2] = a->in6_u.u6_addr32[2] & b->in6_u.u6_addr32[2];
r->in6_u.u6_addr32[3] = a->in6_u.u6_addr32[3] & b->in6_u.u6_addr32[3];
return r;
}
/* a != 0 */
int is_set(struct in6_addr *a)
{
return a->in6_u.u6_addr32[0] ||
a->in6_u.u6_addr32[1] ||
a->in6_u.u6_addr32[2] ||
a->in6_u.u6_addr32[3];
}
/* 1 */
static struct in6_addr one = { .in6_u.u6_addr32 = {0, 0, 0, 1} };
/* print all networks present between address <low> and address <high> in
* cidr format, followed by <eol>.
*/
static void convert_range(struct in6_addr *low, struct in6_addr *high, const char *eol, const char *pfx)
{
int bit;
struct in6_addr r0;
struct in6_addr r1;
if (a_eq_b(low, high)) {
/* single value */
printf("%s%s%s%s\n", pfx?pfx:"", pfx?" ":"", get_ipv6_addr(low), eol);
return;
}
else if (a_gt_b(low, high)) {
struct in6_addr *swap = low;
low = high;
high = swap;
}
if (a_eq_b(low, a_plus_b(high, &one, &r0))) {
/* full range */
printf("%s%s::/0%s\n", pfx?pfx:"", pfx?" ":"", eol);
return;
}
//printf("low=%08x high=%08x\n", low, high);
bit = 0;
while (bit < 128 && a_le_b(a_plus_b(low, hmask(bit, &r0), &r0), high)) {
/* enlarge mask */
if (is_set(a_and_b(low, one_ls_b(bit, &r0), &r0))) {
/* can't aggregate anymore, dump and retry from the same bit */
printf("%s%s%s/%d%s\n", pfx?pfx:"", pfx?" ":"", get_ipv6_addr(low), 128-bit, eol);
a_plus_b(low, one_ls_b(bit, &r0), low);
}
else {
/* try to enlarge the mask as much as possible first */
bit++;
//printf(" ++bit=%d\n", bit);
}
}
//printf("stopped 1 at low=%08x, bit=%d\n", low, bit);
bit = 127;
while (bit >= 0 && is_set(a_plus_b(a_minus_b(high, low, &r0), &one, &r0))) {
/* shrink mask */
if (is_set(a_and_b(a_plus_b(a_minus_b(high, low, &r0), &one, &r0), one_ls_b(bit, &r1), &r1))) {
/* large bit accepted, dump and go on from the same bit */
//printf("max: %08x/%d\n", low, 32-bit);
printf("%s%s%s/%d%s\n", pfx?pfx:"", pfx?" ":"", get_ipv6_addr(low), 128-bit, eol);
a_plus_b(low, one_ls_b(bit, &r0), low);
}
else {
bit--;
//printf(" --bit=%d, low=%08x\n", bit, low);
}
}
//printf("stopped at low=%08x\n", low);
}
static void usage(const char *argv0)
{
fprintf(stderr,
"Usage: %s [<addr> ...] < iplist.csv\n"
"\n"
"This program reads lines starting by two IP addresses and outputs them with\n"
"the two IP addresses replaced by a netmask covering the range between these\n"
"IPs (inclusive). When multiple ranges are needed, as many lines are emitted.\n"
"The IP addresses may be delimited by spaces, tabs or commas. Quotes are\n"
"stripped, and lines beginning with a sharp character ('#') are ignored. The\n"
"IP addresses may be either in the dotted format or represented as a 32-bit\n"
"integer value in network byte order.\n"
"\n"
"For each optional <addr> specified, only the network it belongs to is returned,\n"
"prefixed with the <addr> value.\n"
"\n", argv0);
}
main(int argc, char **argv)
{
char line[MAXLINE];
int l, lnum;
char *lb, *le, *hb, *he, *err;
struct in6_addr sa, da, ta;
if (argc > 1 && *argv[1] == '-') {
usage(argv[0]);
exit(1);
}
lnum = 0;
while (fgets(line, sizeof(line), stdin) != NULL) {
l = strlen(line);
if (l && line[l - 1] == '\n')
line[--l] = '\0';
lnum++;
/* look for the first field which must be the low address of a range,
* in dotted IPv4 format or as an integer. spaces and commas are
* considered as delimiters, quotes are removed.
*/
for (lb = line; *lb == ' ' || *lb == '\t' || *lb == ',' || *lb == '"'; lb++);
if (!*lb || *lb == '#')
continue;
for (le = lb + 1; *le != ' ' && *le != '\t' && *le != ',' && *le != '"' && *le; le++);
if (!*le)
continue;
/* we have the low address between lb(included) and le(excluded) */
*(le++) = 0;
for (hb = le; *hb == ' ' || *hb == '\t' || *hb == ',' || *hb == '"'; hb++);
if (!*hb || *hb == '#')
continue;
for (he = hb + 1; *he != ' ' && *he != '\t' && *he != ',' && *he != '"' && *he; he++);
if (!*he)
continue;
/* we have the high address between hb(included) and he(excluded) */
*(he++) = 0;
/* we want to remove a possible ending quote and a possible comma,
* not more.
*/
while (*he == '"')
*(he++) = ' ';
while (*he == ',' || *he == ' ' || *he == '\t')
*(he++) = ' ';
/* if the trailing string is not empty, prefix it with a space */
if (*(he-1) == ' ')
he--;
if (inet_pton(AF_INET6, lb, &sa) <= 0) {
fprintf(stderr, "Failed to parse source address <%s> at line %d, skipping line\n", lb, lnum);
continue;
}
if (inet_pton(AF_INET6, hb, &da) <= 0) {
fprintf(stderr, "Failed to parse destination address <%s> at line %d, skipping line\n", hb, lnum);
continue;
}
in6_bswap(&sa);
in6_bswap(&da);
if (argc > 1) {
for (l = 1; l < argc; l++) {
if (inet_pton(AF_INET6, argv[l], &da) <= 0)
continue;
in6_bswap(&ta);
if ((a_le_b(&sa, &ta) && a_le_b(&ta, &da)) || (a_le_b(&da, &ta) && a_le_b(&ta, &sa)))
convert_range(&sa, &da, he, argv[l]);
}
}
else {
convert_range(&sa, &da, he, NULL);
}
}
}
CC = gcc
OPTIMIZE = -O3
LDFLAGS = -s
OBJS = iprange
all: $(OBJS)
%: %.c
$(CC) $(LDFLAGS) $(OPTIMIZE) -o $@ $^
clean:
rm -f $(OBJS) *.o *.a *~
/*
* network range to IP+mask converter
*
* Copyright 2011-2012 Willy Tarreau <w@1wt.eu>
*
* This program reads lines starting by two IP addresses and outputs them with
* the two IP addresses replaced by a netmask covering the range between these
* IPs (inclusive). When multiple ranges are needed, as many lines are emitted.
* The IP addresses may be delimited by spaces, tabs or commas. Quotes are
* stripped, and lines beginning with a sharp character ('#') are ignored. The
* IP addresses may be either in the dotted format or represented as a 32-bit
* integer value in network byte order.
*
* 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.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 1024
/* returns a string version of an IPv4 address in host order */
static const char *get_ipv4_addr(unsigned int addr)
{
struct in_addr a;
a.s_addr = ntohl(addr);
return inet_ntoa(a);
}
/* print all networks present between address <low> and address <high> in
* cidr format, followed by <eol>.
*/
static void convert_range(unsigned int low, unsigned int high, const char *eol, const char *pfx)
{
int bit;
if (low == high) {
/* single value */
printf("%s%s%s%s\n", pfx?pfx:"", pfx?" ":"", get_ipv4_addr(low), eol);
return;
}
else if (low > high) {
int swap = low;
low = high;
high = swap;
}
if (low == high + 1) {
/* full range */
printf("%s%s0.0.0.0/0%s\n", pfx?pfx:"", pfx?" ":"", eol);
return;
}
//printf("low=%08x high=%08x\n", low, high);
bit = 0;
while (bit < 32 && low + (1 << bit) - 1 <= high) {
/* enlarge mask */
if (low & (1 << bit)) {
/* can't aggregate anymore, dump and retry from the same bit */
printf("%s%s%s/%d%s\n", pfx?pfx:"", pfx?" ":"", get_ipv4_addr(low), 32-bit, eol);
low += (1 << bit);
}
else {
/* try to enlarge the mask as much as possible first */
bit++;
//printf(" ++bit=%d\n", bit);
}
}
//printf("stopped 1 at low=%08x, bit=%d\n", low, bit);
bit = 31;
while (bit >= 0 && high - low + 1 != 0) {
/* shrink mask */
if ((high - low + 1) & (1 << bit)) {
/* large bit accepted, dump and go on from the same bit */
//printf("max: %08x/%d\n", low, 32-bit);
printf("%s%s%s/%d%s\n", pfx?pfx:"", pfx?" ":"", get_ipv4_addr(low), 32-bit, eol);
low += (1 << bit);
}
else {
bit--;
//printf(" --bit=%d, low=%08x\n", bit, low);
}
}
//printf("stopped at low=%08x\n", low);
}
static void usage(const char *argv0)
{
fprintf(stderr,
"Usage: %s [<addr> ...] < iplist.csv\n"
"\n"
"This program reads lines starting by two IP addresses and outputs them with\n"
"the two IP addresses replaced by a netmask covering the range between these\n"
"IPs (inclusive). When multiple ranges are needed, as many lines are emitted.\n"
"The IP addresses may be delimited by spaces, tabs or commas. Quotes are\n"
"stripped, and lines beginning with a sharp character ('#') are ignored. The\n"
"IP addresses may be either in the dotted format or represented as a 32-bit\n"
"integer value in network byte order.\n"
"\n"
"For each optional <addr> specified, only the network it belongs to is returned,\n"
"prefixed with the <addr> value.\n"
"\n", argv0);
}
main(int argc, char **argv)
{
char line[MAXLINE];
int l, lnum;
char *lb, *le, *hb, *he, *err;
struct in_addr src_addr, dst_addr;
unsigned int sa, da, ta;
if (argc > 1 && *argv[1] == '-') {
usage(argv[0]);
exit(1);
}
lnum = 0;
while (fgets(line, sizeof(line), stdin) != NULL) {
l = strlen(line);
if (l && line[l - 1] == '\n')
line[--l] = '\0';
lnum++;
/* look for the first field which must be the low address of a range,
* in dotted IPv4 format or as an integer. spaces and commas are
* considered as delimiters, quotes are removed.
*/
for (lb = line; *lb == ' ' || *lb == '\t' || *lb == ',' || *lb == '"'; lb++);
if (!*lb || *lb == '#')
continue;
for (le = lb + 1; *le != ' ' && *le != '\t' && *le != ',' && *le != '"' && *le; le++);
if (!*le)
continue;
/* we have the low address between lb(included) and le(excluded) */
*(le++) = 0;
for (hb = le; *hb == ' ' || *hb == '\t' || *hb == ',' || *hb == '"'; hb++);
if (!*hb || *hb == '#')
continue;
for (he = hb + 1; *he != ' ' && *he != '\t' && *he != ',' && *he != '"' && *he; he++);
if (!*he)
continue;
/* we have the high address between hb(included) and he(excluded) */
*(he++) = 0;
/* we want to remove a possible ending quote and a possible comma,
* not more.
*/
while (*he == '"')
*(he++) = ' ';
while (*he == ',' || *he == ' ' || *he == '\t')
*(he++) = ' ';
/* if the trailing string is not empty, prefix it with a space */
if (*(he-1) == ' ')
he--;
if (inet_pton(AF_INET, lb, &src_addr) <= 0) {
/* parsing failed, retry with a plain numeric IP */
src_addr.s_addr = ntohl(strtoul(lb, &err, 10));
if (err && *err) {
fprintf(stderr, "Failed to parse source address <%s> at line %d, skipping line\n", lb, lnum);
continue;
}
}
if (inet_pton(AF_INET, hb, &dst_addr) <= 0) {
/* parsing failed, retry with a plain numeric IP */
dst_addr.s_addr = ntohl(strtoul(hb, &err, 10));
if (err && *err) {
fprintf(stderr, "Failed to parse destination address <%s> at line %d, skipping line\n", hb, lnum);
continue;
}
}
sa = htonl(src_addr.s_addr);
da = htonl(dst_addr.s_addr);
if (argc > 1) {
for (l = 1; l < argc; l++) {
if (inet_pton(AF_INET, argv[l], &dst_addr) <= 0)
continue;
ta = htonl(dst_addr.s_addr);
if ((sa <= ta && ta <= da) || (da <= ta && ta <= sa))
convert_range(sa, da, he, argv[l]);
}
}
else {
convert_range(sa, da, he, NULL);
}
}
}
SNMP support for HAProxy
Copyright 2007-2008 Krzysztof Piotr Oledzki <ole@ans.pl>
Root OID: 1.3.6.1.4.1.29385.106
Files:
- README: this file
- haproxy.pl: Net-SNMP embedded perl module
- haproxy_backend.xml: Cacti snmp-query definition for backends
- haproxy_frontend.xml: Cacti snmp-query definition for frontends
Install:
cp haproxy.pl /etc/snmp/
grep -q "disablePerl false" /etc/snmp/snmpd.conf || echo "disablePerl false" >> /etc/snmp/snmpd.conf
echo "perl do '/etc/snmp/haproxy.pl';" >> /etc/snmp/snmpd.conf
Supported commands:
- GET (snmpget, snmpbulkget): quite fast.
- GETNEXT (snmpwalk, snmpbulkwalk): not so fast as requires to transfer
and parse a lot of data during each step. Always use "get" instead of "walk"
if that's possible.
Supported OIDs:
- 1.3.6.1.4.1.29385.106.1: get a variable from stats
Usage: 1.3.6.1.4.1.29385.106.1.$type.$field.$iid.$sid
- type is one of:
0) frontend
1) backend
2) server
- field is one of:
0..32) CSV format variable
10001) index
10002) unique name
- iid is a proxy id
- sid is a service id (sid): 0 for frontends and backends, >= 1 for servers
- 1.3.6.1.4.1.29385.106.2: get a variable from info
Usage: 1.3.6.1.4.1.29385.106.2.$req.$varnr
- req is one of:
0) get variable name
1) gat variable value
Examples:
- Get a list of frontends (type: 0) with status (field: 17):
$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.1.0.17
SNMPv2-SMI::enterprises.29385.106.1.0.17.1.0 = STRING: "OPEN"
SNMPv2-SMI::enterprises.29385.106.1.0.17.47.0 = STRING: "OPEN"
- Get a list of backends (type: 1) with index (field: 10001):
$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.1.1.10001
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1.0 = STRING: "1.0"
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1100.0 = STRING: "1100.0"
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1101.0 = STRING: "1101.0"
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1200.0 = STRING: "1200.0"
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1201.0 = STRING: "1201.0"
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1300.0 = STRING: "1300.0"
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1400.0 = STRING: "1400.0"
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1401.0 = STRING: "1401.0"
SNMPv2-SMI::enterprises.29385.106.1.1.10001.1500.0 = STRING: "1500.0"
(...)
- Get a list of servers (type: 2) with unique name (field: 10002):
$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.1.2.10002
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1100.1001 = STRING: "backend1/s2"
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1100.1002 = STRING: "backend1/s5"
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1100.1003 = STRING: "backend1/s6"
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1100.1012 = STRING: "backend1/s7"
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1101.1001 = STRING: "backend2/s9"
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1101.1002 = STRING: "backend2/s10"
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1101.1003 = STRING: "backend2/s11"
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1101.1012 = STRING: "backend2/s12"
SNMPv2-SMI::enterprises.29385.106.1.2.10002.1200.1001 = STRING: "backend3/s8"
(...)
- Get a list of servers (type: 2) with weight (field: 18) in proxy 4300:
$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.1.2.18.4300
SNMPv2-SMI::enterprises.29385.106.1.2.18.4300.1001 = STRING: "40"
SNMPv2-SMI::enterprises.29385.106.1.2.18.4300.1002 = STRING: "25"
SNMPv2-SMI::enterprises.29385.106.1.2.18.4300.1003 = STRING: "40"
SNMPv2-SMI::enterprises.29385.106.1.2.18.4300.1012 = STRING: "80"
- Get total sessions count (field: 7) in frontend (type: 1), sid.iid: 47.0 (proxy #47):
snmpget -c public -v2c 192.168.0.1 enterprises.29385.106.1.0.7.47.0
SNMPv2-SMI::enterprises.29385.106.1.0.7.47.0 = STRING: "1014019"
- Get a list of available variables (req: 0):
$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.2.0
SNMPv2-SMI::enterprises.29385.106.2.0.0 = STRING: "Name"
SNMPv2-SMI::enterprises.29385.106.2.0.1 = STRING: "Version"
SNMPv2-SMI::enterprises.29385.106.2.0.2 = STRING: "Release_date"
SNMPv2-SMI::enterprises.29385.106.2.0.3 = STRING: "Nbproc"
SNMPv2-SMI::enterprises.29385.106.2.0.4 = STRING: "Process_num"
SNMPv2-SMI::enterprises.29385.106.2.0.5 = STRING: "Pid"
SNMPv2-SMI::enterprises.29385.106.2.0.6 = STRING: "Uptime"
SNMPv2-SMI::enterprises.29385.106.2.0.7 = STRING: "Uptime_sec"
SNMPv2-SMI::enterprises.29385.106.2.0.8 = STRING: "Memmax_MB"
SNMPv2-SMI::enterprises.29385.106.2.0.9 = STRING: "Ulimit-n"
SNMPv2-SMI::enterprises.29385.106.2.0.10 = STRING: "Maxsock"
SNMPv2-SMI::enterprises.29385.106.2.0.11 = STRING: "Maxconn"
SNMPv2-SMI::enterprises.29385.106.2.0.12 = STRING: "CurrConns"
- Get a variable (req: 1), varnr: 7 (Uptime_sec):
$ snmpget -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.2.1.7
SNMPv2-SMI::enterprises.29385.106.2.1.7 = STRING: "18761"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment