1 diff -aur rp-l2tp-0.4.orig/handlers/cmd.c rp-l2tp-0.4.new/handlers/cmd.c
2 --- rp-l2tp-0.4.orig/handlers/cmd.c 2004-07-01 18:58:56.000000000 +0400
3 +++ rp-l2tp-0.4.new/handlers/cmd.c 2007-03-12 01:48:25.000000000 +0300
7 memcpy(&haddr.sin_addr, he->h_addr, sizeof(haddr.sin_addr));
8 - p = l2tp_peer_find(&haddr, NULL);
9 + p = l2tp_peer_find(&haddr, NULL, peer);
11 cmd_reply(es, fd, "ERR Unknown peer");
13 diff -aur rp-l2tp-0.4.orig/l2tp.h rp-l2tp-0.4.new/l2tp.h
14 --- rp-l2tp-0.4.orig/l2tp.h 2004-07-01 18:58:55.000000000 +0400
15 +++ rp-l2tp-0.4.new/l2tp.h 2007-03-12 03:23:14.000000000 +0300
17 int mask_bits; /* Peer's netmask in number of bits */
18 char hostname[MAX_HOSTNAME]; /* My hostname as presented to this peer. */
19 size_t hostname_len; /* Length of my hostname */
20 + char peer[MAX_HOSTNAME]; /* Peer's name. */
21 + size_t peer_len; /* Length of name */
22 char peername[MAX_HOSTNAME]; /* Peer's hostname. */
23 size_t peername_len; /* Length of hostname */
24 char secret[MAX_SECRET_LEN]; /* Secret for this peer */
28 void l2tp_peer_init(void);
29 -l2tp_peer *l2tp_peer_find(struct sockaddr_in *addr, char const *hostname);
30 +l2tp_peer *l2tp_peer_find(struct sockaddr_in *addr, char const *hostname, char const *peernametosearch);
31 l2tp_peer *l2tp_peer_insert(struct sockaddr_in *addr);
34 diff -aur rp-l2tp-0.4.orig/peer.c rp-l2tp-0.4.new/peer.c
35 --- rp-l2tp-0.4.orig/peer.c 2004-07-01 18:58:55.000000000 +0400
36 +++ rp-l2tp-0.4.new/peer.c 2007-03-12 03:27:17.000000000 +0300
45 static hash_table all_peers;
47 static int handle_secret_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
48 static int handle_hostname_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
49 static int handle_peername_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
50 +static int handle_peer_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
51 static int set_lac_handler(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
52 static int handle_lac_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
53 static int set_lns_handler(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
56 static l2tp_opt_descriptor peer_opts[] = {
58 - { "peer", OPT_TYPE_IPADDR, &prototype.addr.sin_addr.s_addr},
59 + { "peer", OPT_TYPE_CALLFUNC, (void *) handle_peer_option},
60 { "mask", OPT_TYPE_INT, &prototype.mask_bits},
61 { "secret", OPT_TYPE_CALLFUNC, (void *) handle_secret_option},
62 { "hostname", OPT_TYPE_CALLFUNC, (void *) handle_hostname_option},
66 /**********************************************************************
67 +* %FUNCTION: handle_peer_option
69 +* es -- event selector
75 +* Copies peer to prototype
76 +***********************************************************************/
78 +handle_peer_option(EventSelector *es,
79 + l2tp_opt_descriptor *desc,
83 + strncpy(prototype.peer, value, MAX_HOSTNAME);
84 + prototype.peer[MAX_HOSTNAME-1] = 0;
85 + prototype.peer_len = strlen(prototype.peer);
86 + he = gethostbyname(value);
88 + l2tp_set_errmsg("Could not resolve %s as IP address: %s",
89 + value, strerror(errno));
92 + memcpy(&prototype.addr.sin_addr.s_addr, he->h_addr, sizeof(he->h_addr));
96 +/**********************************************************************
97 * %FUNCTION: handle_hostname_option
99 * es -- event selector
101 peer->mask_bits = prototype.mask_bits;
102 memcpy(&peer->hostname,&prototype.hostname, sizeof(prototype.hostname));
103 peer->hostname_len = prototype.hostname_len;
104 + memcpy(&peer->peer,&prototype.peer, sizeof(prototype.peer));
105 + peer->peer_len = prototype.peer_len;
106 memcpy(&peer->peername,&prototype.peername, sizeof(prototype.peername));
107 peer->peername_len = prototype.peername_len;
108 memcpy(&peer->secret, &prototype.secret, MAX_SECRET_LEN);
110 * Searches peer hash table for specified peer.
111 ***********************************************************************/
113 -l2tp_peer_find(struct sockaddr_in *addr, char const *peername)
114 +l2tp_peer_find(struct sockaddr_in *addr, char const *peername, const char *peernametosearch)
117 l2tp_peer *peer = NULL;
119 addr1_str, addr2_str,
120 candidate->mask_bits));
122 - if ((candidate->addr.sin_addr.s_addr & mask) ==
123 - (addr->sin_addr.s_addr & mask)
124 + if (((candidate->addr.sin_addr.s_addr & mask) ==
125 + (addr->sin_addr.s_addr & mask)
126 + || (peernametosearch && candidate->peer[0] && !strcmp(peernametosearch,candidate->peer)))
128 !(candidate->peername[0]) ||
129 !strcmp(peername,candidate->peername))) {
130 diff -aur rp-l2tp-0.4.orig/tunnel.c rp-l2tp-0.4.new/tunnel.c
131 --- rp-l2tp-0.4.orig/tunnel.c 2004-07-01 18:58:56.000000000 +0400
132 +++ rp-l2tp-0.4.new/tunnel.c 2007-03-12 01:50:07.000000000 +0300
133 @@ -1348,7 +1348,7 @@
134 l2tp_debug_tunnel_to_str(tunnel), tunnel->peer_hostname));
137 - tunnel->peer = l2tp_peer_find(&tunnel->peer_addr, tunnel->peer_hostname);
138 + tunnel->peer = l2tp_peer_find(&tunnel->peer_addr, tunnel->peer_hostname, NULL);
140 /* Get assigned tunnel ID */
141 val = l2tp_dgram_search_avp(dgram, tunnel, &mandatory, &hidden, &len,