Guest User

Untitled

a guest
Jan 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1.  /* Create child process, send PADS packet back */
  2.     child = fork();
  3.     if (child < 0) {
  4.     sendErrorPADS(sock, myAddr, packet->ethHdr.h_source,
  5.               TAG_AC_SYSTEM_ERROR, "RP-PPPoE: Server: Unable to start session process");
  6.     pppoe_free_session(cliSession);
  7.     return;
  8.     }
  9.     if (child != 0) {
  10.     /* In the parent process.  Mark pid in session slot */
  11.     cliSession->pid = child;
  12.     Event_HandleChildExit(event_selector, child,
  13.                   childHandler, cliSession);
  14.     control_session_started(cliSession);
  15.     return;
  16.     }
  17.  
  18.     /* In the child process.  */
  19.  
  20.     /* Close all file descriptors except for socket */
  21.     closelog();
  22.     for (i=0; i<CLOSEFD; i++) {
  23.     if (i != sock) {
  24.         close(i);
  25.     }
  26.     }
  27.  
  28.     openlog("pppoe-server", LOG_PID, LOG_DAEMON);
  29.     /* pppd has a nasty habit of killing all processes in its process group.
  30.        Start a new session to stop pppd from killing us! */
  31.     setsid();
  32.  
  33.     /* Send PADS and Start pppd */
  34.     memcpy(pads.ethHdr.h_dest, packet->ethHdr.h_source, ETH_ALEN);
  35.     memcpy(pads.ethHdr.h_source, myAddr, ETH_ALEN);
  36.     pads.ethHdr.h_proto = htons(Eth_PPPOE_Discovery);
  37.     pads.ver = 1;
  38.     pads.type = 1;
  39.     pads.code = CODE_PADS;
  40.  
  41.     pads.session = cliSession->sess;
  42.     plen = 0;
  43.  
  44.     /* Copy requested service name tag back in.  If requested-service name
  45.        length is zero, and we have non-zero services, use first service-name
  46.        as default */
  47.     if (!slen && NumServiceNames) {
  48.     slen = strlen(ServiceNames[0]);
  49.     memcpy(&requestedService.payload, ServiceNames[0], slen);
  50.     requestedService.length = htons(slen);
  51.     }
  52.     memcpy(cursor, &requestedService, TAG_HDR_SIZE+slen);
  53.     cursor += TAG_HDR_SIZE+slen;
  54.     plen += TAG_HDR_SIZE+slen;
  55.  
  56.     if (relayId.type) {
  57.     memcpy(cursor, &relayId, ntohs(relayId.length) + TAG_HDR_SIZE);
  58.     cursor += ntohs(relayId.length) + TAG_HDR_SIZE;
  59.     plen += ntohs(relayId.length) + TAG_HDR_SIZE;
  60.     }
  61.     if (hostUniq.type) {
  62.     memcpy(cursor, &hostUniq, ntohs(hostUniq.length) + TAG_HDR_SIZE);
  63.     cursor += ntohs(hostUniq.length) + TAG_HDR_SIZE;
  64.     plen += ntohs(hostUniq.length) + TAG_HDR_SIZE;
  65.     }
  66.     pads.length = htons(plen);
  67.     sendPacket(NULL, sock, &pads, (int) (plen + HDR_SIZE));
  68.  
  69.     /* Close sock; don't need it any more */
  70.     close(sock);
  71.  
  72.     startPPPD(cliSession);
  73. }
Add Comment
Please, Sign In to add comment