[go: up one dir, main page]

File: proto-pppox.c

package info (click to toggle)
trinity 1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,252 kB
  • ctags: 2,738
  • sloc: ansic: 24,011; sh: 322; makefile: 141
file content (170 lines) | stat: -rw-r--r-- 4,932 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <linux/if.h>
#include <linux/if_ether.h> /* for ETH_ALEN in if_pppox.h */
#include <linux/if_pppox.h>
#include <stdlib.h>
#include "config.h"
#include "net.h"
#include "sanitise.h"

//TODO: Split out each case into separate function.

void pppox_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
{
	struct sockaddr_pppox *pppox;
	struct sockaddr_pppol2tp *pppol2tp;
	unsigned int proto;
	unsigned int i;

	proto = rand() % 3;

	switch (proto) {

	case PX_PROTO_OE:
		pppox = malloc(sizeof(struct sockaddr_pppox));
		if (pppox == NULL)
			return;

		pppox->sa_family = PF_PPPOX;
		pppox->sa_protocol = proto;

		pppox->sa_addr.pppoe.sid = rand();
		for (i = 0; i < ETH_ALEN; i++)
			pppox->sa_addr.pppoe.remote[i] = rand();
		for (i = 0; i < IFNAMSIZ; i++)
			pppox->sa_addr.pppoe.dev[i] = rand();

#ifdef USE_PPPOX_PPTP
		pppox->sa_addr.pptp.call_id = rand();
		pppox->sa_addr.pptp.sin_addr.s_addr = random_ipv4_address();
#endif

		*addr = (struct sockaddr *) pppox;
		*addrlen = sizeof(struct sockaddr_pppox);
		break;

	case PX_PROTO_OL2TP:
		switch (rand() % 4) {

		case 0:	/* PPPoL2TP */
			pppol2tp = malloc(sizeof(struct sockaddr_pppol2tp));
			if (pppol2tp == NULL)
				return;

			pppol2tp->sa_family = PF_PPPOX;
			pppol2tp->sa_protocol = proto;
			pppol2tp->pppol2tp.pid = get_pid();
			pppol2tp->pppol2tp.fd = get_random_fd();
			pppol2tp->pppol2tp.addr.sin_addr.s_addr = random_ipv4_address();
			pppol2tp->pppol2tp.s_tunnel = rand();
			pppol2tp->pppol2tp.s_session = rand();
			pppol2tp->pppol2tp.d_tunnel = rand();
			pppol2tp->pppol2tp.d_session = rand();
			*addr = (struct sockaddr *) pppol2tp;
			*addrlen = sizeof(struct sockaddr_pppol2tp);
			break;

		case 1:	/* PPPoL2TPin6*/
#ifdef USE_PPPOL2TPIN6
			{
			struct sockaddr_pppol2tpin6 *pppol2tpin6;

			pppol2tpin6 = malloc(sizeof(struct sockaddr_pppol2tpin6));
			if (pppol2tpin6 == NULL)
				return;

			pppol2tpin6->sa_family = PF_PPPOX;
			pppol2tpin6->sa_protocol = proto;
			pppol2tpin6->pppol2tp.pid = get_pid();
			pppol2tpin6->pppol2tp.fd = get_random_fd();
			pppol2tpin6->pppol2tp.s_tunnel = rand();
			pppol2tpin6->pppol2tp.s_session = rand();
			pppol2tpin6->pppol2tp.d_tunnel = rand();
			pppol2tpin6->pppol2tp.d_session = rand();
			pppol2tpin6->pppol2tp.addr.sin6_family = AF_INET6;
			pppol2tpin6->pppol2tp.addr.sin6_port = rand();
			pppol2tpin6->pppol2tp.addr.sin6_flowinfo = rand();
			pppol2tpin6->pppol2tp.addr.sin6_addr.s6_addr32[0] = 0;
			pppol2tpin6->pppol2tp.addr.sin6_addr.s6_addr32[1] = 0;
			pppol2tpin6->pppol2tp.addr.sin6_addr.s6_addr32[2] = 0;
			pppol2tpin6->pppol2tp.addr.sin6_addr.s6_addr32[3] = htonl(1);
			pppol2tpin6->pppol2tp.addr.sin6_scope_id = rand();
			*addr = (struct sockaddr *) pppol2tpin6;
			*addrlen = sizeof(struct sockaddr_pppol2tpin6);
			}
#endif
			break;

		case 2:	/* PPPoL2TPv3*/
#ifdef USE_PPPOL2TPV3
			{
			struct sockaddr_pppol2tpv3 *pppol2tpv3;

			pppol2tpv3 = malloc(sizeof(struct sockaddr_pppol2tpv3));
			if (pppol2tpv3 == NULL)
				return;

			pppol2tpv3->sa_family = PF_PPPOX;
			pppol2tpv3->sa_protocol = proto;
			pppol2tpv3->pppol2tp.pid = get_pid();
			pppol2tpv3->pppol2tp.fd = get_random_fd();
			pppol2tpv3->pppol2tp.addr.sin_addr.s_addr = random_ipv4_address();
			pppol2tpv3->pppol2tp.s_tunnel = rand();
			pppol2tpv3->pppol2tp.s_session = rand();
			pppol2tpv3->pppol2tp.d_tunnel = rand();
			pppol2tpv3->pppol2tp.d_session = rand();
			*addr = (struct sockaddr *) pppol2tpv3;
			*addrlen = sizeof(struct sockaddr_pppol2tpv3);
			}
#endif
			break;

		case 3:	/* PPPoL2TPv3in6 */
#ifdef USE_PPPOL2TPIN6
			{
			struct sockaddr_pppol2tpv3in6 *pppol2tpv3in6;

			pppol2tpv3in6 = malloc(sizeof(struct sockaddr_pppol2tpv3in6));
			if (pppol2tpv3in6 == NULL)
				return;

			pppol2tpv3in6->sa_family = PF_PPPOX;
			pppol2tpv3in6->sa_protocol = proto;
			pppol2tpv3in6->pppol2tp.pid = get_pid();
			pppol2tpv3in6->pppol2tp.fd = get_random_fd();
			pppol2tpv3in6->pppol2tp.s_tunnel = rand();
			pppol2tpv3in6->pppol2tp.s_session = rand();
			pppol2tpv3in6->pppol2tp.d_tunnel = rand();
			pppol2tpv3in6->pppol2tp.d_session = rand();
			pppol2tpv3in6->pppol2tp.addr.sin6_family = AF_INET6;
			pppol2tpv3in6->pppol2tp.addr.sin6_port = rand();
			pppol2tpv3in6->pppol2tp.addr.sin6_flowinfo = rand();
			pppol2tpv3in6->pppol2tp.addr.sin6_addr.s6_addr32[0] = 0;
			pppol2tpv3in6->pppol2tp.addr.sin6_addr.s6_addr32[1] = 0;
			pppol2tpv3in6->pppol2tp.addr.sin6_addr.s6_addr32[2] = 0;
			pppol2tpv3in6->pppol2tp.addr.sin6_addr.s6_addr32[3] = random_ipv4_address();
			pppol2tpv3in6->pppol2tp.addr.sin6_scope_id = rand();
			*addr = (struct sockaddr *) pppol2tpv3in6;
			*addrlen = sizeof(struct sockaddr_pppol2tpv3in6);
			}
#endif
			break;

		default:
			break;
		}


#ifdef USE_PPPOX_PPTP
	case PX_PROTO_PPTP:
		//FIXME: What do we do here?
		break;
#endif

	default:
		break;
	}
}