pppd: add option to set custom host-uniq pppoe tag
[openwrt/staging/yousong.git] / package / network / services / ppp / patches / 520-uniq.patch
1 --- a/pppd/plugins/rp-pppoe/common.c
2 +++ b/pppd/plugins/rp-pppoe/common.c
3 @@ -121,13 +121,13 @@ sendPADT(PPPoEConnection *conn, char con
4 /* If we're using Host-Uniq, copy it over */
5 if (conn->useHostUniq) {
6 PPPoETag hostUniq;
7 - pid_t pid = getpid();
8 + int len = strlen(conn->useHostUniq);
9 hostUniq.type = htons(TAG_HOST_UNIQ);
10 - hostUniq.length = htons(sizeof(pid));
11 - memcpy(hostUniq.payload, &pid, sizeof(pid));
12 - memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
13 - cursor += sizeof(pid) + TAG_HDR_SIZE;
14 - plen += sizeof(pid) + TAG_HDR_SIZE;
15 + hostUniq.length = htons(len);
16 + memcpy(hostUniq.payload, conn->useHostUniq, len);
17 + memcpy(cursor, &hostUniq, len + TAG_HDR_SIZE);
18 + cursor += len + TAG_HDR_SIZE;
19 + plen += len + TAG_HDR_SIZE;
20 }
21
22 /* Copy error message */
23 --- a/pppd/plugins/rp-pppoe/discovery.c
24 +++ b/pppd/plugins/rp-pppoe/discovery.c
25 @@ -104,7 +104,7 @@ parseForHostUniq(UINT16_t type, UINT16_t
26 static int
27 packetIsForMe(PPPoEConnection *conn, PPPoEPacket *packet)
28 {
29 - int forMe = 0;
30 + char *uniq = conn->useHostUniq;
31
32 /* If packet is not directed to our MAC address, forget it */
33 if (memcmp(packet->ethHdr.h_dest, conn->myEth, ETH_ALEN)) return 0;
34 @@ -112,8 +112,8 @@ packetIsForMe(PPPoEConnection *conn, PPP
35 /* If we're not using the Host-Unique tag, then accept the packet */
36 if (!conn->useHostUniq) return 1;
37
38 - parsePacket(packet, parseForHostUniq, &forMe);
39 - return forMe;
40 + parsePacket(packet, parseForHostUniq, &uniq);
41 + return uniq != 0;
42 }
43
44 /**********************************************************************
45 @@ -303,14 +303,14 @@ sendPADI(PPPoEConnection *conn)
46 /* If we're using Host-Uniq, copy it over */
47 if (conn->useHostUniq) {
48 PPPoETag hostUniq;
49 - pid_t pid = getpid();
50 + int len = strlen(conn->useHostUniq);
51 hostUniq.type = htons(TAG_HOST_UNIQ);
52 - hostUniq.length = htons(sizeof(pid));
53 - memcpy(hostUniq.payload, &pid, sizeof(pid));
54 - CHECK_ROOM(cursor, packet.payload, sizeof(pid) + TAG_HDR_SIZE);
55 - memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
56 - cursor += sizeof(pid) + TAG_HDR_SIZE;
57 - plen += sizeof(pid) + TAG_HDR_SIZE;
58 + hostUniq.length = htons(len);
59 + memcpy(hostUniq.payload, conn->useHostUniq, len);
60 + CHECK_ROOM(cursor, packet.payload, len + TAG_HDR_SIZE);
61 + memcpy(cursor, &hostUniq, len + TAG_HDR_SIZE);
62 + cursor += len + TAG_HDR_SIZE;
63 + plen += len + TAG_HDR_SIZE;
64 }
65
66 /* Add our maximum MTU/MRU */
67 @@ -480,14 +480,14 @@ sendPADR(PPPoEConnection *conn)
68 /* If we're using Host-Uniq, copy it over */
69 if (conn->useHostUniq) {
70 PPPoETag hostUniq;
71 - pid_t pid = getpid();
72 + int len = strlen(conn->useHostUniq);
73 hostUniq.type = htons(TAG_HOST_UNIQ);
74 - hostUniq.length = htons(sizeof(pid));
75 - memcpy(hostUniq.payload, &pid, sizeof(pid));
76 - CHECK_ROOM(cursor, packet.payload, sizeof(pid)+TAG_HDR_SIZE);
77 - memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
78 - cursor += sizeof(pid) + TAG_HDR_SIZE;
79 - plen += sizeof(pid) + TAG_HDR_SIZE;
80 + hostUniq.length = htons(len);
81 + memcpy(hostUniq.payload, conn->useHostUniq, len);
82 + CHECK_ROOM(cursor, packet.payload, len+TAG_HDR_SIZE);
83 + memcpy(cursor, &hostUniq, len + TAG_HDR_SIZE);
84 + cursor += len + TAG_HDR_SIZE;
85 + plen += len + TAG_HDR_SIZE;
86 }
87
88 /* Add our maximum MTU/MRU */
89 --- a/pppd/plugins/rp-pppoe/plugin.c
90 +++ b/pppd/plugins/rp-pppoe/plugin.c
91 @@ -65,6 +65,7 @@ static char *existingSession = NULL;
92 static int printACNames = 0;
93 static char *pppoe_reqd_mac = NULL;
94 unsigned char pppoe_reqd_mac_addr[6];
95 +static char *host_uniq = NULL;
96
97 static int PPPoEDevnameHook(char *cmd, char **argv, int doit);
98 static option_t Options[] = {
99 @@ -82,6 +83,8 @@ static option_t Options[] = {
100 "Be verbose about discovered access concentrators"},
101 { "pppoe-mac", o_string, &pppoe_reqd_mac,
102 "Only connect to specified MAC address" },
103 + { "host-uniq", o_string, &host_uniq,
104 + "Specify custom Host-Uniq" },
105 { NULL }
106 };
107 int (*OldDevnameHook)(char *cmd, char **argv, int doit) = NULL;
108 @@ -107,7 +110,7 @@ PPPOEInitDevice(void)
109 conn->ifName = devnam;
110 conn->discoverySocket = -1;
111 conn->sessionSocket = -1;
112 - conn->useHostUniq = 1;
113 + conn->useHostUniq = NULL;
114 conn->printACNames = printACNames;
115 conn->discoveryTimeout = PADI_TIMEOUT;
116 return 1;
117 @@ -163,6 +166,9 @@ PPPOEConnectDevice(void)
118 if (lcp_wantoptions[0].mru > ifr.ifr_mtu - TOTAL_OVERHEAD)
119 lcp_wantoptions[0].mru = ifr.ifr_mtu - TOTAL_OVERHEAD;
120
121 + if(host_uniq)
122 + conn->useHostUniq = host_uniq;
123 +
124 conn->acName = acName;
125 conn->serviceName = pppd_pppoe_service;
126 strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam));
127 --- a/pppd/plugins/rp-pppoe/pppoe-discovery.c
128 +++ b/pppd/plugins/rp-pppoe/pppoe-discovery.c
129 @@ -641,7 +641,7 @@ int main(int argc, char *argv[])
130
131 memset(conn, 0, sizeof(PPPoEConnection));
132
133 - while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
134 + while ((opt = getopt(argc, argv, "I:D:VUW:AS:C:h")) > 0) {
135 switch(opt) {
136 case 'S':
137 conn->serviceName = xstrdup(optarg);
138 @@ -650,7 +650,19 @@ int main(int argc, char *argv[])
139 conn->acName = xstrdup(optarg);
140 break;
141 case 'U':
142 - conn->useHostUniq = 1;
143 + if(conn->useHostUniq) {
144 + fprintf(stderr, "-U and -W are mutually exclusive\n");
145 + exit(EXIT_FAILURE);
146 + }
147 + conn->useHostUniq = malloc(12);
148 + snprintf(conn->useHostUniq, 12, "%d", getpid());
149 + break;
150 + case 'W':
151 + if(conn->useHostUniq) {
152 + fprintf(stderr, "-U and -W are mutually exclusive\n");
153 + exit(EXIT_FAILURE);
154 + }
155 + conn->useHostUniq = xstrdup(optarg);
156 break;
157 case 'D':
158 conn->debugFile = fopen(optarg, "w");
159 --- a/pppd/plugins/rp-pppoe/pppoe.h
160 +++ b/pppd/plugins/rp-pppoe/pppoe.h
161 @@ -224,7 +224,7 @@ typedef struct PPPoEConnectionStruct {
162 char *serviceName; /* Desired service name, if any */
163 char *acName; /* Desired AC name, if any */
164 int synchronous; /* Use synchronous PPP */
165 - int useHostUniq; /* Use Host-Uniq tag */
166 + char *useHostUniq; /* Use Host-Uniq tag */
167 int printACNames; /* Just print AC names */
168 FILE *debugFile; /* Debug file for dumping packets */
169 int numPADOs; /* Number of PADO packets received */