added little utility to mark all outgoing packets of a program with a FW mark
This commit is contained in:
parent
9d61959f82
commit
efe6526b02
2 changed files with 50 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
*.o
|
*.o
|
||||||
*~
|
*~
|
||||||
|
mark.so
|
||||||
|
|
49
project/mark.c
Normal file
49
project/mark.c
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/** Wrapper utility to mark all sockets of a program
|
||||||
|
*
|
||||||
|
* Compile:
|
||||||
|
* gcc -fPIC -c -o mark.o mark.c
|
||||||
|
* gcc -shared -o mark.so mark.o -ldl
|
||||||
|
*
|
||||||
|
* Use:
|
||||||
|
* LD_PRELOAD="./soft_atimes.so" command
|
||||||
|
*
|
||||||
|
* @author Steffen Vogel <post@steffenvogel.de>
|
||||||
|
* @authir D.J. Capelis
|
||||||
|
* @copyright 2014-2015, Steffen Vogel
|
||||||
|
* @copyright 2007, Regents of the University of California
|
||||||
|
* @license GPLv3
|
||||||
|
*********************************************************************************/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
typedef int (*socket_t)(int domain, int type, int protocol);
|
||||||
|
|
||||||
|
static socket_t _socket;
|
||||||
|
|
||||||
|
int socket(int domain, int type, int protocol)
|
||||||
|
{
|
||||||
|
if (!_socket)
|
||||||
|
_socket = (socket_t) dlsym(RTLD_NEXT, "socket");
|
||||||
|
|
||||||
|
int sd = _socket(domain, type, protocol);
|
||||||
|
|
||||||
|
if (sd >= 0) {
|
||||||
|
if (domain == AF_INET || domain == AF_INET6) {
|
||||||
|
char * env = getenv("MARK");
|
||||||
|
int mark = env ? atoi(env) : 0xCD;
|
||||||
|
|
||||||
|
printf("Setting SO_MARK for fd=%u to %#x\n", sd, mark);
|
||||||
|
|
||||||
|
setsockopt(sd, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sd;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue