static int connect_pppoe_ses(void) { int i,err=-1; if( pppoe_server == 1 ){ srv_init_ses(ses,devnam); }else{ client_init_ses(ses,devnam); } strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam)); err= session_connect ( ses ); if(err < 0){ poe_fatal(ses,"Failed to negotiate PPPoE connection: %d %m",errno,errno); } poe_info(ses,"Connecting PPPoE socket: %E %04x %s %p", ses->sp.sa_addr.pppoe.remote, ses->sp.sa_addr.pppoe.sid, ses->sp.sa_addr.pppoe.dev,ses); err = connect(ses->fd, (struct sockaddr*)&ses->sp, sizeof(struct sockaddr_pppox)); if( err < 0 ){ poe_fatal(ses,"Failed to connect PPPoE socket: %d %m",errno,errno); return err; } /* Once the logging is fixed, print a message here indicating connection parameters */ return ses->fd; }
int relay_init_ses(struct session *ses, char* from, char* to) { int retval = client_init_ses(ses, from); if(retval<0) return retval; ses->fwd_sock = socket(PF_PACKET, SOCK_DGRAM, 0); if( ses->fwd_sock < 0 ) { poe_fatal(ses,"Cannot create PF_PACKET socket for PPPoE forwarding\n"); } /* Verify the device name , construct ses->local */ retval = get_sockaddr_ll(to, &ses->remote); if (retval < 0) poe_fatal(ses,"relay_init_ses:get_sockaddr_ll failed %m"); retval = bind( ses->fwd_sock , (struct sockaddr*)&ses->remote, sizeof(struct sockaddr_ll)); if( retval < 0 ){ poe_fatal(ses,"bind to PF_PACKET socket failed: %m"); } memcpy(ses->fwd_name, to, IFNAMSIZ); memcpy(ses->name, from, IFNAMSIZ); ses->init_disc = relay_init_disc; ses->rcv_padi = relay_rcv_padi; ses->rcv_pado = relay_rcv_pkt; ses->rcv_padr = relay_rcv_pkt; ses->rcv_pads = relay_rcv_pads; ses->rcv_padt = relay_rcv_padt; }
static int connect_pppoe_ses(void) { int err=-1; if( pppoe_server == 1 ){ srv_init_ses(ses,devnam); }else{ client_init_ses(ses,devnam); } #if 0 ses->np=1; /* jamal debug the discovery portion */ #endif strcpy(ppp_devnam, devnam); err= session_connect ( ses ); if(err < 0){ if (!kill_link) poe_error(ses,"Failed to negotiate PPPoE connection: %d - %m", errno,errno); return -1; } poe_info(ses,"Connecting PPPoE socket: %E %04x %s %p", ses->sp.sa_addr.pppoe.remote, ses->sp.sa_addr.pppoe.sid, ses->sp.sa_addr.pppoe.dev,ses); err = connect(ses->fd, (struct sockaddr*)&ses->sp, sizeof(struct sockaddr_pppox)); if( err < 0 ){ poe_fatal(ses,"Failed to connect PPPoE socket: %d %m",errno,errno); return err; } #if 0 if (ses->np) fatal("discovery complete\n"); #endif /* Once the logging is fixed, print a message here indicating connection parameters */ return ses->fd; }
int main(int argc, char** argv){ int ret; struct filter *filt; struct session *ses = (struct session *)malloc(sizeof(struct session)); char buf[256]; ses=(void *)malloc(sizeof(struct session)); if(!ses){ return -1; } memset(ses,0,sizeof(struct session)); openlog ("pppoed", LOG_PID | LOG_NDELAY, LOG_PPPOE); setlogmask (LOG_UPTO (ses->opt_debug ? LOG_DEBUG : LOG_INFO)); if ((get_args (argc,(char **) argv,ses)) <1) poe_die(-1); filt=ses->filt; /* makes the code more readable */ if (!ses->np) { poe_create_pidfile (ses); // signal (SIGINT, &sigproc); // signal (SIGTERM, &sigproc); signal (SIGCHLD, &sigchild); } if(ses->type == SESSION_CLIENT){ poe_info(ses,"calling client_init_ses\n"); ret = client_init_ses(ses,ses->name); if( ret < 0 ){ return -1; } while (ses->filt->num_restart > 0) { poe_info(ses,"Restart number %d ",ses->filt->num_restart); ppp_connect (ses); ses->filt->num_restart--; } }else if( ses->type == SESSION_SERVER ){ poe_info(ses,"calling srv_init_ses\n"); ret = srv_init_ses(ses,ses->name); if( ret < 0 ){ return -1; } ret = 1; while(ret>=0) ret = ppp_connect(ses); } poe_info(ses,"ppp_connect came back! %d",ret); exit(0); }
static int connect_pppoe_ses(void) { int err=-1; int rcvbuf; //brcm // cwu #if 0 if( pppoe_server == 1 ){ srv_init_ses(ses,devnam); }else{ client_init_ses(ses,devnam); } #endif client_init_ses(ses,devnam); #if 0 ses->np=1; /* jamal debug the discovery portion */ #endif strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam)); //brcm if (disc_sock > 0) { rcvbuf=5000; setsockopt(disc_sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)); } err= session_connect ( ses ); /* * brcm, after pppoe session is up, we don't read disc_sock, * reduce socket rx buffer to avoid to exhaust all rx buffer */ if (disc_sock > 0) { rcvbuf=256; setsockopt(disc_sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)); } if(err < 0){ if (!link_up(devnam)) return 0; else if (!get_sock_intf(devnam)) return 0; else poe_fatal(ses,"Failed to negotiate PPPoE connection: %d %m",errno,errno); } // cwu /* poe_info(ses,"Connecting PPPoE socket: %E %04x %s %p", ses->sp.sa_addr.pppoe.remote, ses->sp.sa_addr.pppoe.sid, ses->sp.sa_addr.pppoe.dev,ses); */ err = connect(ses->fd, (struct sockaddr*)&ses->sp, sizeof(struct sockaddr_pppox)); if( err < 0 ){ poe_fatal(ses,"Failed to connect PPPoE socket: %d %m",errno,errno); return err; } #if 0 if (ses->np) fatal("discovery complete\n"); #endif /* Once the logging is fixed, print a message here indicating connection parameters */ return ses->fd; }
/** add by [email protected] call it before do connection */ static void pre_connect_pppoe_ses(void) { //add by [email protected] unsigned int mac[6]; unsigned int sID; FILE* sfile; int n; //disconnect before. added by [email protected] if (access (SESSION_FILE, F_OK) != 0) { return; } client_init_ses(ses,devnam); strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam)); sfile = fopen(SESSION_FILE, "r"); n = fscanf(sfile, "%u:%2x:%2x:%2x:%2x:%2x:%2x", &sID, &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); fclose(sfile); if (n < 7) { poe_info(ses, "Read PPPoE Session error!"); return; } struct pppoe_packet padt; memset(&padt, 0, sizeof(struct pppoe_packet)); ses->remote.sll_addr[0] = mac[0]; ses->remote.sll_addr[1] = mac[1]; ses->remote.sll_addr[2] = mac[2]; ses->remote.sll_addr[3] = mac[3]; ses->remote.sll_addr[4] = mac[4]; ses->remote.sll_addr[5] = mac[5]; memcpy(&padt.addr, &ses->remote, sizeof(struct sockaddr_ll)); padt.hdr = (struct pppoe_hdr*) ses->curr_pkt.buf; padt.hdr->ver = 1; padt.hdr->type = 1; padt.hdr->code = PADT_CODE; padt.hdr->sid = htons(sID); send_disc(ses, &padt); ses->sp.sa_addr.pppoe.sid = 0; connect(ses->fd, (struct sockaddr*)&ses->sp, sizeof(struct sockaddr_pppox)); usleep(2000000); /** int ret; warn("Doing pre-disconnect"); session_disconnect(ses); ses->sp.sa_addr.pppoe.sid = 0; ret = connect(ses->fd, (struct sockaddr*)&ses->sp, sizeof(struct sockaddr_pppox)); */ }