File: mod_ip_tos.c

package info (click to toggle)
fragroute 1.2-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 692 kB
  • ctags: 520
  • sloc: ansic: 4,331; sh: 2,842; makefile: 74
file content (69 lines) | stat: -rw-r--r-- 1,182 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * mod_ip_tos.c
 *
 * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
 *
 * $Id: mod_ip_tos.c,v 1.3 2002/04/07 22:55:20 dugsong Exp $
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "argv.h"
#include "mod.h"
#include "pkt.h"

struct ip_tos_data {
	int	tos;
};

void *
ip_tos_close(void *d)
{
	if (d != NULL)
		free(d);
	return (NULL);
}

void *
ip_tos_open(int argc, char *argv[])
{
	struct ip_tos_data *data;

	if (argc != 2)
		return (NULL);

	if ((data = calloc(1, sizeof(*data))) == NULL)
		return (NULL);

	if (sscanf(argv[1], "%i", &data->tos) != 1 ||
	    data->tos < 0 || data->tos > 255)
		return (ip_tos_close(data));

	return (data);
}

int
ip_tos_apply(void *d, struct pktq *pktq)
{
	struct ip_tos_data *data = (struct ip_tos_data *)d;
	struct pkt *pkt;

	TAILQ_FOREACH(pkt, pktq, pkt_next) {
		pkt->pkt_ip->ip_tos = data->tos;
		/* XXX - do incremental checksum */
		ip_checksum(pkt->pkt_ip, pkt->pkt_ip_data - pkt->pkt_eth_data);
	}
	return (0);
}

struct mod mod_ip_tos = {
	"ip_tos",			/* name */
	"ip_tos <tos>",			/* usage */
	ip_tos_open,			/* open */
	ip_tos_apply,			/* apply */
	ip_tos_close			/* close */
};