Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Create child process, send PADS packet back */
- child = fork();
- if (child < 0) {
- sendErrorPADS(sock, myAddr, packet->ethHdr.h_source,
- TAG_AC_SYSTEM_ERROR, "RP-PPPoE: Server: Unable to start session process");
- pppoe_free_session(cliSession);
- return;
- }
- if (child != 0) {
- /* In the parent process. Mark pid in session slot */
- cliSession->pid = child;
- Event_HandleChildExit(event_selector, child,
- childHandler, cliSession);
- control_session_started(cliSession);
- return;
- }
- /* In the child process. */
- /* Close all file descriptors except for socket */
- closelog();
- for (i=0; i<CLOSEFD; i++) {
- if (i != sock) {
- close(i);
- }
- }
- openlog("pppoe-server", LOG_PID, LOG_DAEMON);
- /* pppd has a nasty habit of killing all processes in its process group.
- Start a new session to stop pppd from killing us! */
- setsid();
- /* Send PADS and Start pppd */
- memcpy(pads.ethHdr.h_dest, packet->ethHdr.h_source, ETH_ALEN);
- memcpy(pads.ethHdr.h_source, myAddr, ETH_ALEN);
- pads.ethHdr.h_proto = htons(Eth_PPPOE_Discovery);
- pads.ver = 1;
- pads.type = 1;
- pads.code = CODE_PADS;
- pads.session = cliSession->sess;
- plen = 0;
- /* Copy requested service name tag back in. If requested-service name
- length is zero, and we have non-zero services, use first service-name
- as default */
- if (!slen && NumServiceNames) {
- slen = strlen(ServiceNames[0]);
- memcpy(&requestedService.payload, ServiceNames[0], slen);
- requestedService.length = htons(slen);
- }
- memcpy(cursor, &requestedService, TAG_HDR_SIZE+slen);
- cursor += TAG_HDR_SIZE+slen;
- plen += TAG_HDR_SIZE+slen;
- if (relayId.type) {
- memcpy(cursor, &relayId, ntohs(relayId.length) + TAG_HDR_SIZE);
- cursor += ntohs(relayId.length) + TAG_HDR_SIZE;
- plen += ntohs(relayId.length) + TAG_HDR_SIZE;
- }
- if (hostUniq.type) {
- memcpy(cursor, &hostUniq, ntohs(hostUniq.length) + TAG_HDR_SIZE);
- cursor += ntohs(hostUniq.length) + TAG_HDR_SIZE;
- plen += ntohs(hostUniq.length) + TAG_HDR_SIZE;
- }
- pads.length = htons(plen);
- sendPacket(NULL, sock, &pads, (int) (plen + HDR_SIZE));
- /* Close sock; don't need it any more */
- close(sock);
- startPPPD(cliSession);
- }
Add Comment
Please, Sign In to add comment