109-debian_pppoe_cleanup.patch 31 KB

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