103-debian_pppoe_cleanup.patch 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. Index: ppp-2.4.3/pppd/plugins/rp-pppoe/common.c
  2. ===================================================================
  3. --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/common.c 2007-06-04 13:22:08.391579568 +0200
  4. +++ ppp-2.4.3/pppd/plugins/rp-pppoe/common.c 2007-06-04 13:22:09.414424072 +0200
  5. @@ -18,10 +18,6 @@
  6. #include "pppoe.h"
  7. -#ifdef HAVE_SYSLOG_H
  8. -#include <syslog.h>
  9. -#endif
  10. -
  11. #include <string.h>
  12. #include <errno.h>
  13. #include <stdlib.h>
  14. @@ -50,17 +46,17 @@
  15. UINT16_t tagType, tagLen;
  16. if (packet->ver != 1) {
  17. - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
  18. + error("Invalid PPPoE version (%u)", packet->ver);
  19. return -1;
  20. }
  21. if (packet->type != 1) {
  22. - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
  23. + error("Invalid PPPoE type (%u)", packet->type);
  24. return -1;
  25. }
  26. /* Do some sanity checks on packet */
  27. if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
  28. - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
  29. + error("Invalid PPPoE packet length (%u)", len);
  30. return -1;
  31. }
  32. @@ -76,7 +72,7 @@
  33. return 0;
  34. }
  35. if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
  36. - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
  37. + error("Invalid PPPoE tag length (%u)", tagLen);
  38. return -1;
  39. }
  40. func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
  41. @@ -105,17 +101,17 @@
  42. UINT16_t tagType, tagLen;
  43. if (packet->ver != 1) {
  44. - syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
  45. + error("Invalid PPPoE version (%u)", packet->ver);
  46. return NULL;
  47. }
  48. if (packet->type != 1) {
  49. - syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
  50. + error("Invalid PPPoE type (%u)", packet->type);
  51. return NULL;
  52. }
  53. /* Do some sanity checks on packet */
  54. if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
  55. - syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
  56. + error("Invalid PPPoE packet length (%u)", len);
  57. return NULL;
  58. }
  59. @@ -131,7 +127,7 @@
  60. return NULL;
  61. }
  62. if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
  63. - syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
  64. + error("Invalid PPPoE tag length (%u)", tagLen);
  65. return NULL;
  66. }
  67. if (tagType == type) {
  68. @@ -143,6 +139,7 @@
  69. return NULL;
  70. }
  71. +#ifdef unused
  72. /**********************************************************************
  73. *%FUNCTION: printErr
  74. *%ARGUMENTS:
  75. @@ -158,6 +155,7 @@
  76. fprintf(stderr, "pppoe: %s\n", str);
  77. syslog(LOG_ERR, "%s", str);
  78. }
  79. +#endif
  80. /**********************************************************************
  81. @@ -172,7 +170,7 @@
  82. {
  83. char *copy = malloc(strlen(str)+1);
  84. if (!copy) {
  85. - rp_fatal("strdup failed");
  86. + fatal("strdup failed");
  87. }
  88. strcpy(copy, str);
  89. return copy;
  90. @@ -467,9 +465,10 @@
  91. fprintf(conn->debugFile, "\n");
  92. fflush(conn->debugFile);
  93. }
  94. - syslog(LOG_INFO,"Sent PADT");
  95. + info("Sent PADT");
  96. }
  97. +#ifdef unused
  98. /**********************************************************************
  99. *%FUNCTION: parseLogErrs
  100. *%ARGUMENTS:
  101. @@ -501,4 +500,5 @@
  102. break;
  103. }
  104. }
  105. +#endif
  106. Index: ppp-2.4.3/pppd/plugins/rp-pppoe/discovery.c
  107. ===================================================================
  108. --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/discovery.c 2007-06-04 13:22:09.225452800 +0200
  109. +++ ppp-2.4.3/pppd/plugins/rp-pppoe/discovery.c 2007-06-04 13:22:09.414424072 +0200
  110. @@ -13,10 +13,6 @@
  111. #include "pppoe.h"
  112. -#ifdef HAVE_SYSLOG_H
  113. -#include <syslog.h>
  114. -#endif
  115. -
  116. #include <string.h>
  117. #include <stdlib.h>
  118. #include <errno.h>
  119. @@ -167,24 +163,21 @@
  120. if (conn->printACNames) {
  121. printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
  122. } else {
  123. - syslog(LOG_ERR, "PADO: Service-Name-Error: %.*s", (int) len, data);
  124. - exit(1);
  125. + fatal("PADO: Service-Name-Error: %.*s", (int) len, data);
  126. }
  127. break;
  128. case TAG_AC_SYSTEM_ERROR:
  129. if (conn->printACNames) {
  130. printf("Got a System-Error tag: %.*s\n", (int) len, data);
  131. } else {
  132. - syslog(LOG_ERR, "PADO: System-Error: %.*s", (int) len, data);
  133. - exit(1);
  134. + fatal("PADO: System-Error: %.*s", (int) len, data);
  135. }
  136. break;
  137. case TAG_GENERIC_ERROR:
  138. if (conn->printACNames) {
  139. printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
  140. } else {
  141. - syslog(LOG_ERR, "PADO: Generic-Error: %.*s", (int) len, data);
  142. - exit(1);
  143. + fatal("PADO: Generic-Error: %.*s", (int) len, data);
  144. }
  145. break;
  146. }
  147. @@ -209,20 +202,14 @@
  148. PPPoEConnection *conn = (PPPoEConnection *) extra;
  149. switch(type) {
  150. case TAG_SERVICE_NAME:
  151. - syslog(LOG_DEBUG, "PADS: Service-Name: '%.*s'", (int) len, data);
  152. + dbglog("PADS: Service-Name: '%.*s'", (int) len, data);
  153. break;
  154. case TAG_SERVICE_NAME_ERROR:
  155. - syslog(LOG_ERR, "PADS: Service-Name-Error: %.*s", (int) len, data);
  156. - fprintf(stderr, "PADS: Service-Name-Error: %.*s\n", (int) len, data);
  157. - exit(1);
  158. + fatal("PADS: Service-Name-Error: %.*s", (int) len, data);
  159. case TAG_AC_SYSTEM_ERROR:
  160. - syslog(LOG_ERR, "PADS: System-Error: %.*s", (int) len, data);
  161. - fprintf(stderr, "PADS: System-Error: %.*s\n", (int) len, data);
  162. - exit(1);
  163. + fatal("PADS: System-Error: %.*s", (int) len, data);
  164. case TAG_GENERIC_ERROR:
  165. - syslog(LOG_ERR, "PADS: Generic-Error: %.*s", (int) len, data);
  166. - fprintf(stderr, "PADS: Generic-Error: %.*s\n", (int) len, data);
  167. - exit(1);
  168. + fatal("PADS: Generic-Error: %.*s", (int) len, data);
  169. case TAG_RELAY_SESSION_ID:
  170. conn->relayId.type = htons(type);
  171. conn->relayId.length = htons(len);
  172. @@ -336,7 +323,7 @@
  173. if (r >= 0 || errno != EINTR) break;
  174. }
  175. if (r < 0) {
  176. - fatalSys("select (waitForPADO)");
  177. + fatal("waitForPADO: select: %m");
  178. }
  179. if (r == 0) return; /* Timed out */
  180. }
  181. @@ -346,8 +333,7 @@
  182. /* Check length */
  183. if (ntohs(packet.length) + HDR_SIZE > len) {
  184. - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
  185. - (unsigned int) ntohs(packet.length));
  186. + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
  187. continue;
  188. }
  189. @@ -366,16 +352,16 @@
  190. if (packet.code == CODE_PADO) {
  191. if (BROADCAST(packet.ethHdr.h_source)) {
  192. - printErr("Ignoring PADO packet from broadcast MAC address");
  193. + error("Ignoring PADO packet from broadcast MAC address");
  194. continue;
  195. }
  196. parsePacket(&packet, parsePADOTags, &pc);
  197. if (!pc.seenACName) {
  198. - printErr("Ignoring PADO packet with no AC-Name tag");
  199. + error("Ignoring PADO packet with no AC-Name tag");
  200. continue;
  201. }
  202. if (!pc.seenServiceName) {
  203. - printErr("Ignoring PADO packet with no Service-Name tag");
  204. + error("Ignoring PADO packet with no Service-Name tag");
  205. continue;
  206. }
  207. conn->numPADOs++;
  208. @@ -513,7 +499,7 @@
  209. if (r >= 0 || errno != EINTR) break;
  210. }
  211. if (r < 0) {
  212. - fatalSys("select (waitForPADS)");
  213. + fatal("waitForPADS: select: %m");
  214. }
  215. if (r == 0) return;
  216. }
  217. @@ -523,8 +509,7 @@
  218. /* Check length */
  219. if (ntohs(packet.length) + HDR_SIZE > len) {
  220. - syslog(LOG_ERR, "Bogus PPPoE length field (%u)",
  221. - (unsigned int) ntohs(packet.length));
  222. + error("Bogus PPPoE length field (%u)", ntohs(packet.length));
  223. continue;
  224. }
  225. @@ -556,11 +541,12 @@
  226. /* Don't bother with ntohs; we'll just end up converting it back... */
  227. conn->session = packet.session;
  228. - syslog(LOG_INFO, "PPP session is %d", (int) ntohs(conn->session));
  229. + info("PPP session is %d", ntohs(conn->session));
  230. /* RFC 2516 says session id MUST NOT be zero or 0xFFFF */
  231. if (ntohs(conn->session) == 0 || ntohs(conn->session) == 0xFFFF) {
  232. - syslog(LOG_ERR, "Access concentrator used a session value of %x -- the AC is violating RFC 2516", (unsigned int) ntohs(conn->session));
  233. + error("Access concentrator used a session value of 0x%x"
  234. + " -- the AC is violating RFC 2516", ntohs(conn->session));
  235. }
  236. }
  237. @@ -620,7 +606,7 @@
  238. /* If we're only printing access concentrator names, we're done */
  239. if (conn->printACNames) {
  240. - die(0);
  241. + exit(0);
  242. }
  243. timeout = PADI_TIMEOUT;
  244. Index: ppp-2.4.3/pppd/plugins/rp-pppoe/if.c
  245. ===================================================================
  246. --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/if.c 2007-06-04 13:22:08.402577896 +0200
  247. +++ ppp-2.4.3/pppd/plugins/rp-pppoe/if.c 2007-06-04 13:22:09.416423768 +0200
  248. @@ -40,10 +40,6 @@
  249. #include <sys/ioctl.h>
  250. #endif
  251. -#ifdef HAVE_SYSLOG_H
  252. -#include <syslog.h>
  253. -#endif
  254. -
  255. #include <errno.h>
  256. #include <stdlib.h>
  257. #include <string.h>
  258. @@ -127,7 +123,7 @@
  259. {
  260. UINT16_t type = (UINT16_t) ntohs(packet->ethHdr.h_proto);
  261. if (type != Eth_PPPOE_Discovery && type != Eth_PPPOE_Session) {
  262. - syslog(LOG_ERR, "Invalid ether type 0x%x", type);
  263. + error("Invalid ethernet type 0x%x", type);
  264. }
  265. return type;
  266. }
  267. @@ -156,7 +152,7 @@
  268. ifc.ifc_len = sizeof(inbuf);
  269. ifc.ifc_buf = inbuf;
  270. if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
  271. - fatalSys("SIOCGIFCONF");
  272. + fatal("SIOCGIFCONF: %m");
  273. }
  274. ifr = ifc.ifc_req;
  275. ifreq.ifr_name[0] = '\0';
  276. @@ -172,9 +168,7 @@
  277. (sdl->sdl_alen == ETH_ALEN) &&
  278. !strncmp(ifname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
  279. if (found) {
  280. - char buffer[256];
  281. - sprintf(buffer, "interface %.16s has more than one ethernet address", ifname);
  282. - rp_fatal(buffer);
  283. + fatal("interface %s has more than one ethernet address", ifname);
  284. } else {
  285. found = 1;
  286. memcpy(hwaddr, LLADDR(sdl), ETH_ALEN);
  287. @@ -183,9 +177,7 @@
  288. }
  289. }
  290. if (!found) {
  291. - char buffer[256];
  292. - sprintf(buffer, "interface %.16s has no ethernet address", ifname);
  293. - rp_fatal(buffer);
  294. + fatal("interface %s has no ethernet address", ifname);
  295. }
  296. }
  297. @@ -252,7 +244,7 @@
  298. /* Apply the filter */
  299. if (ioctl(fd, BIOCSETF, &bpfProgram) < 0) {
  300. - fatalSys("ioctl(BIOCSETF)");
  301. + fatal("ioctl(BIOCSETF): %m");
  302. }
  303. }
  304. }
  305. @@ -298,42 +290,36 @@
  306. if (fd < 0) {
  307. switch (errno) {
  308. case EACCES: /* permission denied */
  309. - {
  310. - char buffer[256];
  311. - sprintf(buffer, "Cannot open %.32s -- pppoe must be run as root.", bpfName);
  312. - rp_fatal(buffer);
  313. - }
  314. + fatal("Cannot open %s -- pppoe must be run as root.", bpfName);
  315. break;
  316. case EBUSY:
  317. case ENOENT: /* no such file */
  318. if (i == 0) {
  319. - rp_fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
  320. + fatal("No /dev/bpf* devices (check your kernel configuration for BPF support)");
  321. } else {
  322. - rp_fatal("All /dev/bpf* devices are in use");
  323. + fatal("All /dev/bpf* devices are in use");
  324. }
  325. break;
  326. }
  327. - fatalSys(bpfName);
  328. + fatal("%s: %m", bpfName);
  329. }
  330. if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
  331. - fatalSys("socket");
  332. + fatal("socket: %m");
  333. }
  334. /* Check that the interface is up */
  335. strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  336. if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
  337. - fatalSys("ioctl(SIOCGIFFLAGS)");
  338. + fatal("ioctl(SIOCGIFFLAGS): %m");
  339. }
  340. if ((ifr.ifr_flags & IFF_UP) == 0) {
  341. - char buffer[256];
  342. - sprintf(buffer, "Interface %.16s is not up\n", ifname);
  343. - rp_fatal(buffer);
  344. + fatal("Interface %s is not up", ifname);
  345. }
  346. /* Fill in hardware address and initialize the packet filter rules */
  347. if (hwaddr == NULL) {
  348. - rp_fatal("openInterface: no hwaddr arg.");
  349. + fatal("openInterface: no hwaddr arg.");
  350. }
  351. getHWaddr(sock, ifname, hwaddr);
  352. initFilter(fd, type, hwaddr);
  353. @@ -342,58 +328,52 @@
  354. #if !defined(__OpenBSD__)
  355. strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  356. if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) {
  357. - fatalSys("ioctl(SIOCGIFMTU)");
  358. + fatal("ioctl(SIOCGIFMTU): %m");
  359. }
  360. if (ifr.ifr_mtu < ETH_DATA_LEN) {
  361. - char buffer[256];
  362. - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
  363. + error("Interface %s has MTU of %d -- should be %d."
  364. + " You may have serious connection problems.",
  365. ifname, ifr.ifr_mtu, ETH_DATA_LEN);
  366. - printErr(buffer);
  367. }
  368. #endif
  369. /* done with the socket */
  370. if (close(sock) < 0) {
  371. - fatalSys("close");
  372. + fatal("close: %m");
  373. }
  374. /* Check the BPF version number */
  375. if (ioctl(fd, BIOCVERSION, &bpf_ver) < 0) {
  376. - fatalSys("ioctl(BIOCVERSION)");
  377. + fatal("ioctl(BIOCVERSION): %m");
  378. }
  379. if ((bpf_ver.bv_major != BPF_MAJOR_VERSION) ||
  380. (bpf_ver.bv_minor < BPF_MINOR_VERSION)) {
  381. - char buffer[256];
  382. - sprintf(buffer, "Unsupported BPF version: %d.%d (kernel: %d.%d)",
  383. + fatal("Unsupported BPF version: %d.%d (kernel: %d.%d)",
  384. BPF_MAJOR_VERSION, BPF_MINOR_VERSION,
  385. bpf_ver.bv_major, bpf_ver.bv_minor);
  386. - rp_fatal(buffer);
  387. }
  388. /* allocate a receive packet buffer */
  389. if (ioctl(fd, BIOCGBLEN, &bpfLength) < 0) {
  390. - fatalSys("ioctl(BIOCGBLEN)");
  391. + fatal("ioctl(BIOCGBLEN): %m");
  392. }
  393. if (!(bpfBuffer = (unsigned char *) malloc(bpfLength))) {
  394. - rp_fatal("malloc");
  395. + fatal("malloc");
  396. }
  397. /* reads should return as soon as there is a packet available */
  398. optval = 1;
  399. if (ioctl(fd, BIOCIMMEDIATE, &optval) < 0) {
  400. - fatalSys("ioctl(BIOCIMMEDIATE)");
  401. + fatal("ioctl(BIOCIMMEDIATE): %m");
  402. }
  403. /* Bind the interface to the filter */
  404. strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  405. if (ioctl(fd, BIOCSETIF, &ifr) < 0) {
  406. - char buffer[256];
  407. - sprintf(buffer, "ioctl(BIOCSETIF) can't select interface %.16s",
  408. - ifname);
  409. - rp_fatal(buffer);
  410. + fatal("ioctl(BIOCSETIF) can't select interface %s: %m", ifname);
  411. }
  412. - syslog(LOG_INFO, "Interface=%.16s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%.32s Buffer size=%d",
  413. + info("Interface=%s HWaddr=%02X:%02X:%02X:%02X:%02X:%02X Device=%s Buffer size=%d",
  414. ifname,
  415. hwaddr[0], hwaddr[1], hwaddr[2],
  416. hwaddr[3], hwaddr[4], hwaddr[5],
  417. @@ -442,48 +422,41 @@
  418. if ((fd = socket(domain, stype, htons(type))) < 0) {
  419. /* Give a more helpful message for the common error case */
  420. if (errno == EPERM) {
  421. - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
  422. + fatal("Cannot create raw socket -- pppoe must be run as root.");
  423. }
  424. - fatalSys("socket");
  425. + fatal("cannot create the raw socket: %m");
  426. }
  427. if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
  428. - fatalSys("setsockopt");
  429. + fatal("setsockopt(SOL_SOCKET, SO_BROADCAST): %m");
  430. }
  431. /* Fill in hardware address */
  432. if (hwaddr) {
  433. strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  434. - if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
  435. - fatalSys("ioctl(SIOCGIFHWADDR)");
  436. - }
  437. + if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
  438. + fatal("ioctl(SIOCGIFHWADDR): %m");
  439. memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
  440. #ifdef ARPHRD_ETHER
  441. if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
  442. - char buffer[256];
  443. - sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
  444. - rp_fatal(buffer);
  445. + fatal("Interface %s is not Ethernet", ifname);
  446. }
  447. #endif
  448. if (NOT_UNICAST(hwaddr)) {
  449. - char buffer[256];
  450. - sprintf(buffer,
  451. - "Interface %.16s has broadcast/multicast MAC address??",
  452. + fatal("Interface %s has broadcast/multicast MAC address",
  453. ifname);
  454. - rp_fatal(buffer);
  455. }
  456. }
  457. /* Sanity check on MTU */
  458. strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  459. if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
  460. - fatalSys("ioctl(SIOCGIFMTU)");
  461. + fatal("ioctl(SIOCGIFMTU): %m");
  462. }
  463. if (ifr.ifr_mtu < ETH_DATA_LEN) {
  464. - char buffer[256];
  465. - sprintf(buffer, "Interface %.16s has MTU of %d -- should be %d. You may have serious connection problems.",
  466. + error("Interface %s has MTU of %d -- should be %d."
  467. + " You may have serious connection problems.",
  468. ifname, ifr.ifr_mtu, ETH_DATA_LEN);
  469. - printErr(buffer);
  470. }
  471. #ifdef HAVE_STRUCT_SOCKADDR_LL
  472. @@ -493,7 +466,7 @@
  473. strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  474. if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
  475. - fatalSys("ioctl(SIOCFIGINDEX): Could not get interface index");
  476. + fatal("ioctl(SIOCFIGINDEX): Could not get interface index: %m");
  477. }
  478. sa.sll_ifindex = ifr.ifr_ifindex;
  479. @@ -503,7 +476,7 @@
  480. /* We're only interested in packets on specified interface */
  481. if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
  482. - fatalSys("bind");
  483. + fatal("bind: %m");
  484. }
  485. return fd;
  486. @@ -527,13 +500,11 @@
  487. {
  488. #if defined(USE_BPF)
  489. if (write(sock, pkt, size) < 0) {
  490. - sysErr("write (sendPacket)");
  491. - return -1;
  492. + fatal("sendPacket: write: %m");
  493. }
  494. #elif defined(HAVE_STRUCT_SOCKADDR_LL)
  495. if (send(sock, pkt, size, 0) < 0) {
  496. - sysErr("send (sendPacket)");
  497. - return -1;
  498. + fatal("sendPacket: send: %m");
  499. }
  500. #else
  501. #ifdef USE_DLPI
  502. @@ -577,12 +548,11 @@
  503. struct sockaddr sa;
  504. if (!conn) {
  505. - rp_fatal("relay and server not supported on Linux 2.0 kernels");
  506. + fatal("relay and server not supported on Linux 2.0 kernels");
  507. }
  508. strcpy(sa.sa_data, conn->ifName);
  509. if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
  510. - sysErr("sendto (sendPacket)");
  511. - return -1;
  512. + fatal("sendPacket: sendto: %m");
  513. }
  514. #endif
  515. #endif
  516. @@ -632,26 +602,24 @@
  517. if (bpfSize <= 0) {
  518. bpfOffset = 0;
  519. if ((bpfSize = read(sock, bpfBuffer, bpfLength)) < 0) {
  520. - sysErr("read (receivePacket)");
  521. - return -1;
  522. + fatal("receivePacket: read: %m");
  523. }
  524. }
  525. if (bpfSize < sizeof(hdr)) {
  526. - syslog(LOG_ERR, "Truncated bpf packet header: len=%d", bpfSize);
  527. + error("Truncated bpf packet header: len=%d", bpfSize);
  528. clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
  529. return 0;
  530. }
  531. memcpy(&hdr, bpfBuffer + bpfOffset, sizeof(hdr));
  532. if (hdr.bh_caplen != hdr.bh_datalen) {
  533. - syslog(LOG_ERR, "Truncated bpf packet: caplen=%d, datalen=%d",
  534. + error("Truncated bpf packet: caplen=%d, datalen=%d",
  535. hdr.bh_caplen, hdr.bh_datalen);
  536. clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
  537. return 0;
  538. }
  539. seglen = hdr.bh_hdrlen + hdr.bh_caplen;
  540. if (seglen > bpfSize) {
  541. - syslog(LOG_ERR, "Truncated bpf packet: seglen=%d, bpfSize=%d",
  542. - seglen, bpfSize);
  543. + error("Truncated bpf packet: seglen=%d, bpfSize=%d", seglen, bpfSize);
  544. clearPacketHeader(pkt); /* resets bpfSize and bpfOffset */
  545. return 0;
  546. }
  547. @@ -676,16 +644,14 @@
  548. data.len = 0;
  549. if ((retval = getmsg(sock, NULL, &data, &flags)) < 0) {
  550. - sysErr("read (receivePacket)");
  551. - return -1;
  552. + fatal("receivePacket: getmsg: %m");
  553. }
  554. *size = data.len;
  555. #else
  556. if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
  557. - sysErr("recv (receivePacket)");
  558. - return -1;
  559. + fatal("receivePacket: recv: %m");
  560. }
  561. #endif
  562. #endif
  563. @@ -716,7 +682,7 @@
  564. int ppa;
  565. if(strlen(ifname) > PATH_MAX) {
  566. - rp_fatal("socket: string to long");
  567. + fatal("openInterface: interface name too long");
  568. }
  569. ppa = atoi(&ifname[strlen(ifname)-1]);
  570. @@ -729,9 +695,9 @@
  571. if (( fd = open(base_dev, O_RDWR)) < 0) {
  572. /* Give a more helpful message for the common error case */
  573. if (errno == EPERM) {
  574. - rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
  575. + fatal("Cannot create raw socket -- pppoe must be run as root.");
  576. }
  577. - fatalSys("socket");
  578. + fatal("open(%s): %m", base_dev);
  579. }
  580. /* rearranged order of DLPI code - delphys 20010803 */
  581. @@ -747,17 +713,18 @@
  582. dl_abssaplen = ABS(dlp->info_ack.dl_sap_length);
  583. dl_saplen = dlp->info_ack.dl_sap_length;
  584. if (ETHERADDRL != (dlp->info_ack.dl_addr_length - dl_abssaplen))
  585. - fatalSys("invalid destination physical address length");
  586. + fatal("invalid destination physical address length");
  587. dl_addrlen = dl_abssaplen + ETHERADDRL;
  588. /* ethernet address retrieved as part of DL_INFO_ACK - delphys 20010803 */
  589. memcpy(hwaddr, (u_char*)((char*)(dlp) + (int)(dlp->info_ack.dl_addr_offset)), ETHERADDRL);
  590. if ( strioctl(fd, DLIOCRAW, -1, 0, NULL) < 0 ) {
  591. - fatalSys("DLIOCRAW");
  592. + fatal("DLIOCRAW: %m");
  593. }
  594. - if (ioctl(fd, I_FLUSH, FLUSHR) < 0) fatalSys("I_FLUSH");
  595. + if (ioctl(fd, I_FLUSH, FLUSHR) < 0)
  596. + fatal("I_FLUSH: %m");
  597. return fd;
  598. }
  599. @@ -780,7 +747,7 @@
  600. flags = 0;
  601. if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
  602. - fatalSys("dlpromiscon: putmsg");
  603. + fatal("dlpromiscon: putmsg: %m");
  604. }
  605. @@ -799,7 +766,7 @@
  606. flags = RS_HIPRI;
  607. if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
  608. - fatalSys("dlinforeq: putmsg");
  609. + fatal("dlinforeq: putmsg: %m");
  610. }
  611. void dlunitdatareq(int fd, u_char *addrp, int addrlen, u_long minpri, u_long maxpri, u_char *datap, int datalen)
  612. @@ -827,7 +794,7 @@
  613. data.buf = (char *) datap;
  614. if (putmsg(fd, &ctl, &data, 0) < 0)
  615. - fatalSys("dlunitdatareq: putmsg");
  616. + fatal("dlunitdatareq: putmsg: %m");
  617. }
  618. void dlinfoack(int fd, char *bufp)
  619. @@ -847,18 +814,14 @@
  620. expecting(DL_INFO_ACK, dlp);
  621. if (ctl.len < sizeof (dl_info_ack_t)) {
  622. - char buffer[256];
  623. - sprintf(buffer, "dlinfoack: response ctl.len too short: %d", ctl.len);
  624. - rp_fatal(buffer);
  625. + fatal("dlinfoack: response ctl.len too short: %d", ctl.len);
  626. }
  627. if (flags != RS_HIPRI)
  628. - rp_fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
  629. + fatal("dlinfoack: DL_INFO_ACK was not M_PCPROTO");
  630. if (ctl.len < sizeof (dl_info_ack_t)) {
  631. - char buffer[256];
  632. - sprintf(buffer, "dlinfoack: short response ctl.len: %d", ctl.len);
  633. - rp_fatal(buffer);
  634. + fatal("dlinfoack: short response ctl.len: %d", ctl.len);
  635. }
  636. }
  637. @@ -882,7 +845,7 @@
  638. flags = 0;
  639. if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
  640. - fatalSys("dlbindreq: putmsg");
  641. + fatal("dlbindreq: putmsg: %m");
  642. }
  643. void dlattachreq(int fd, u_long ppa)
  644. @@ -901,7 +864,7 @@
  645. flags = 0;
  646. if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0)
  647. - fatalSys("dlattachreq: putmsg");
  648. + fatal("dlattachreq: putmsg: %m");
  649. }
  650. void dlokack(int fd, char *bufp)
  651. @@ -921,18 +884,14 @@
  652. expecting(DL_OK_ACK, dlp);
  653. if (ctl.len < sizeof (dl_ok_ack_t)) {
  654. - char buffer[256];
  655. - sprintf(buffer, "dlokack: response ctl.len too short: %d", ctl.len);
  656. - rp_fatal(buffer);
  657. + fatal("dlokack: response ctl.len too short: %d", ctl.len);
  658. }
  659. if (flags != RS_HIPRI)
  660. - rp_fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
  661. + fatal("dlokack: DL_OK_ACK was not M_PCPROTO");
  662. if (ctl.len < sizeof (dl_ok_ack_t)) {
  663. - char buffer[256];
  664. - sprintf(buffer, "dlokack: short response ctl.len: %d", ctl.len);
  665. - rp_fatal(buffer);
  666. + fatal("dlokack: short response ctl.len: %d", ctl.len);
  667. }
  668. }
  669. @@ -953,12 +912,10 @@
  670. expecting(DL_BIND_ACK, dlp);
  671. if (flags != RS_HIPRI)
  672. - rp_fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
  673. + fatal("dlbindack: DL_OK_ACK was not M_PCPROTO");
  674. if (ctl.len < sizeof (dl_bind_ack_t)) {
  675. - char buffer[256];
  676. - sprintf(buffer, "dlbindack: short response ctl.len: %d", ctl.len);
  677. - rp_fatal(buffer);
  678. + fatal("dlbindack: short response ctl.len: %d", ctl.len);
  679. }
  680. }
  681. @@ -989,8 +946,7 @@
  682. */
  683. (void) signal(SIGALRM, sigalrm);
  684. if (alarm(MAXWAIT) < 0) {
  685. - (void) sprintf(errmsg, "%s: alarm", caller);
  686. - fatalSys(errmsg);
  687. + fatal("%s: alarm", caller);
  688. }
  689. /*
  690. @@ -998,61 +954,48 @@
  691. */
  692. *flagsp = 0;
  693. if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) {
  694. - (void) sprintf(errmsg, "%s: getmsg", caller);
  695. - fatalSys(errmsg);
  696. + fatal(errmsg, "%s: getmsg: %m", caller);
  697. }
  698. /*
  699. * Stop timer.
  700. */
  701. if (alarm(0) < 0) {
  702. - (void) sprintf(errmsg, "%s: alarm", caller);
  703. - fatalSys(errmsg);
  704. + fatal("%s: alarm", caller);
  705. }
  706. /*
  707. * Check for MOREDATA and/or MORECTL.
  708. */
  709. if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) {
  710. - char buffer[256];
  711. - sprintf(buffer, "%s: MORECTL|MOREDATA", caller);
  712. - rp_fatal(buffer);
  713. + fatal("%s: MORECTL|MOREDATA", caller);
  714. }
  715. if (rc & MORECTL) {
  716. - char buffer[256];
  717. - sprintf(buffer, "%s: MORECTL", caller);
  718. - rp_fatal(buffer);
  719. + fatal("%s: MORECTL", caller);
  720. }
  721. if (rc & MOREDATA) {
  722. - char buffer[256];
  723. - sprintf(buffer, "%s: MOREDATA", caller);
  724. - rp_fatal(buffer);
  725. + fatal("%s: MOREDATA", caller);
  726. }
  727. /*
  728. * Check for at least sizeof (long) control data portion.
  729. */
  730. if (ctlp->len < sizeof (long)) {
  731. - char buffer[256];
  732. - sprintf(buffer, "getmsg: control portion length < sizeof (long): %d", ctlp->len);
  733. - rp_fatal(buffer);
  734. + fatal("getmsg: control portion length < sizeof (long): %d", ctlp->len);
  735. }
  736. }
  737. void sigalrm(int sig)
  738. {
  739. - (void) rp_fatal("sigalrm: TIMEOUT");
  740. + fatal("sigalrm: TIMEOUT");
  741. }
  742. void expecting(int prim, union DL_primitives *dlp)
  743. {
  744. if (dlp->dl_primitive != (u_long)prim) {
  745. - char buffer[256];
  746. - sprintf(buffer, "expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
  747. - rp_fatal(buffer);
  748. - exit(1);
  749. + fatal("expected %s got %s", dlprim(prim), dlprim(dlp->dl_primitive));
  750. }
  751. }
  752. Index: ppp-2.4.3/pppd/plugins/rp-pppoe/Makefile.linux
  753. ===================================================================
  754. --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/Makefile.linux 2007-06-04 13:22:08.408576984 +0200
  755. +++ ppp-2.4.3/pppd/plugins/rp-pppoe/Makefile.linux 2007-06-04 13:22:09.416423768 +0200
  756. @@ -28,8 +28,8 @@
  757. CFLAGS=$(COPTS) -I../../../include/linux
  758. all: rp-pppoe.so pppoe-discovery
  759. -pppoe-discovery: libplugin.a pppoe-discovery.o
  760. - $(CC) -o pppoe-discovery pppoe-discovery.o libplugin.a
  761. +pppoe-discovery: pppoe-discovery.o utils.o libplugin.a
  762. + $(CC) -o pppoe-discovery pppoe-discovery.o utils.o libplugin.a
  763. pppoe-discovery.o: pppoe-discovery.c
  764. $(CC) $(CFLAGS) '-DVERSION="$(VERSION)"' -c -o pppoe-discovery.o pppoe-discovery.c
  765. Index: ppp-2.4.3/pppd/plugins/rp-pppoe/plugin.c
  766. ===================================================================
  767. --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/plugin.c 2007-06-04 13:22:08.414576072 +0200
  768. +++ ppp-2.4.3/pppd/plugins/rp-pppoe/plugin.c 2007-06-04 13:22:09.417423616 +0200
  769. @@ -35,7 +35,6 @@
  770. #include "pppd/pathnames.h"
  771. #include <linux/types.h>
  772. -#include <syslog.h>
  773. #include <sys/ioctl.h>
  774. #include <sys/types.h>
  775. #include <sys/socket.h>
  776. @@ -173,10 +172,8 @@
  777. (unsigned) conn->peerEth[5]);
  778. if (connect(conn->sessionSocket, (struct sockaddr *) &sp,
  779. - sizeof(struct sockaddr_pppox)) < 0) {
  780. + sizeof(struct sockaddr_pppox)) < 0)
  781. fatal("Failed to connect PPPoE socket: %d %m", errno);
  782. - return -1;
  783. - }
  784. return conn->sessionSocket;
  785. }
  786. @@ -365,11 +362,9 @@
  787. }
  788. add_options(Options);
  789. -
  790. - info("RP-PPPoE plugin version %s compiled against pppd %s",
  791. - RP_VERSION, VERSION);
  792. }
  793. +#ifdef unused
  794. /**********************************************************************
  795. *%FUNCTION: fatalSys
  796. *%ARGUMENTS:
  797. @@ -423,6 +418,7 @@
  798. {
  799. rp_fatal(str);
  800. }
  801. +#endif
  802. struct channel pppoe_channel = {
  803. Index: ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe-discovery.c
  804. ===================================================================
  805. --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/pppoe-discovery.c 2007-06-04 13:22:08.420575160 +0200
  806. +++ ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe-discovery.c 2007-06-04 13:22:09.417423616 +0200
  807. @@ -17,14 +17,8 @@
  808. #include "pppoe.h"
  809. -char *xstrdup(const char *s);
  810. void usage(void);
  811. -void die(int status)
  812. -{
  813. - exit(status);
  814. -}
  815. -
  816. int main(int argc, char *argv[])
  817. {
  818. int opt;
  819. @@ -32,17 +26,17 @@
  820. conn = malloc(sizeof(PPPoEConnection));
  821. if (!conn)
  822. - fatalSys("malloc");
  823. + fatal("malloc");
  824. memset(conn, 0, sizeof(PPPoEConnection));
  825. while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
  826. switch(opt) {
  827. case 'S':
  828. - conn->serviceName = xstrdup(optarg);
  829. + conn->serviceName = strDup(optarg);
  830. break;
  831. case 'C':
  832. - conn->acName = xstrdup(optarg);
  833. + conn->acName = strDup(optarg);
  834. break;
  835. case 'U':
  836. conn->useHostUniq = 1;
  837. @@ -57,7 +51,7 @@
  838. fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
  839. break;
  840. case 'I':
  841. - conn->ifName = xstrdup(optarg);
  842. + conn->ifName = strDup(optarg);
  843. break;
  844. case 'A':
  845. /* this is the default */
  846. @@ -74,7 +68,7 @@
  847. /* default interface name */
  848. if (!conn->ifName)
  849. - conn->ifName = strdup("eth0");
  850. + conn->ifName = strDup("eth0");
  851. conn->discoverySocket = -1;
  852. conn->sessionSocket = -1;
  853. @@ -84,39 +78,6 @@
  854. exit(0);
  855. }
  856. -void rp_fatal(char const *str)
  857. -{
  858. - char buf[1024];
  859. -
  860. - printErr(str);
  861. - sprintf(buf, "pppoe-discovery: %.256s", str);
  862. - exit(1);
  863. -}
  864. -
  865. -void fatalSys(char const *str)
  866. -{
  867. - char buf[1024];
  868. - int i = errno;
  869. -
  870. - sprintf(buf, "%.256s: %.256s", str, strerror(i));
  871. - printErr(buf);
  872. - sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
  873. - exit(1);
  874. -}
  875. -
  876. -void sysErr(char const *str)
  877. -{
  878. - rp_fatal(str);
  879. -}
  880. -
  881. -char *xstrdup(const char *s)
  882. -{
  883. - register char *ret = strdup(s);
  884. - if (!ret)
  885. - sysErr("strdup");
  886. - return ret;
  887. -}
  888. -
  889. void usage(void)
  890. {
  891. fprintf(stderr, "Usage: pppoe-discovery [options]\n");
  892. Index: ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe.h
  893. ===================================================================
  894. --- ppp-2.4.3.orig/pppd/plugins/rp-pppoe/pppoe.h 2007-06-04 13:22:08.426574248 +0200
  895. +++ ppp-2.4.3/pppd/plugins/rp-pppoe/pppoe.h 2007-06-04 13:22:09.418423464 +0200
  896. @@ -307,12 +307,18 @@
  897. unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType,
  898. PPPoETag *tag);
  899. +void dbglog(char *, ...); /* log a debug message */
  900. +void info(char *, ...); /* log an informational message */
  901. +void warn(char *, ...); /* log a warning message */
  902. +void error(char *, ...); /* log an error message */
  903. +void fatal(char *, ...); /* log an error message and die(1) */
  904. +
  905. #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
  906. #define CHECK_ROOM(cursor, start, len) \
  907. do {\
  908. if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
  909. - syslog(LOG_ERR, "Would create too-long packet"); \
  910. + error("Would create too-long packet"); \
  911. return; \
  912. } \
  913. } while(0)
  914. Index: ppp-2.4.3/pppd/plugins/rp-pppoe/utils.c
  915. ===================================================================
  916. --- /dev/null 1970-01-01 00:00:00.000000000 +0000
  917. +++ ppp-2.4.3/pppd/plugins/rp-pppoe/utils.c 2007-06-04 13:22:09.418423464 +0200
  918. @@ -0,0 +1,62 @@
  919. +#include <stdio.h>
  920. +#include <stdlib.h>
  921. +#include <unistd.h>
  922. +#include <stdarg.h>
  923. +#include <syslog.h>
  924. +
  925. +void dbglog(const char *fmt, ...)
  926. +{
  927. + va_list ap;
  928. +
  929. + va_start(ap, fmt);
  930. + vsyslog(LOG_DEBUG, fmt, ap);
  931. + vfprintf(stderr, fmt, ap);
  932. + fputs("\n", stderr);
  933. + va_end(ap);
  934. +}
  935. +
  936. +void info(const char *fmt, ...)
  937. +{
  938. + va_list ap;
  939. +
  940. + va_start(ap, fmt);
  941. + vsyslog(LOG_INFO, fmt, ap);
  942. + vfprintf(stderr, fmt, ap);
  943. + fputs("\n", stderr);
  944. + va_end(ap);
  945. +}
  946. +
  947. +void warn(const char *fmt, ...)
  948. +{
  949. + va_list ap;
  950. +
  951. + va_start(ap, fmt);
  952. + vsyslog(LOG_WARNING, fmt, ap);
  953. + vfprintf(stderr, fmt, ap);
  954. + fputs("\n", stderr);
  955. + va_end(ap);
  956. +}
  957. +
  958. +void error(const char *fmt, ...)
  959. +{
  960. + va_list ap;
  961. +
  962. + va_start(ap, fmt);
  963. + vsyslog(LOG_ERR, fmt, ap);
  964. + vfprintf(stderr, fmt, ap);
  965. + fputs("\n", stderr);
  966. + va_end(ap);
  967. +}
  968. +
  969. +void fatal(const char *fmt, ...)
  970. +{
  971. + va_list ap;
  972. +
  973. + va_start(ap, fmt);
  974. + vsyslog(LOG_ERR, fmt, ap);
  975. + vfprintf(stderr, fmt, ap);
  976. + fputs("\n", stderr);
  977. + va_end(ap);
  978. + exit(1);
  979. +}
  980. +