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; }
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; }
int client_init_ses (struct session *ses, char* devnam) { int i=0; int retval; char dev[IFNAMSIZ+1]; int addr[ETH_ALEN]; int sid; /* do error checks here; session name etc are valid */ // poe_info (ses,"init_ses: creating socket"); /* Make socket if necessary */ if( disc_sock < 0 ){ disc_sock = socket(PF_PACKET, SOCK_DGRAM, 0); if( disc_sock < 0 ){ poe_fatal(ses, "Cannot create PF_PACKET socket for PPPoE discovery\n"); } } /* Check for long format */ retval =sscanf(devnam, FMTSTRING(IFNAMSIZ),addr, addr+1, addr+2, addr+3, addr+4, addr+5,&sid,dev); if( retval != 8 ){ /* Verify the device name , construct ses->local */ retval = get_sockaddr_ll(devnam,&ses->local); if (retval < 0) poe_fatal(ses, "client_init_ses: " "Cannot create PF_PACKET socket for PPPoE discovery\n"); ses->state = PADO_CODE; create_msg(BCM_PPPOE_CLIENT_STATE_PADO); memcpy(&ses->remote, &ses->local, sizeof(struct sockaddr_ll) ); memset( ses->remote.sll_addr, 0xff, ETH_ALEN); }else{ /* long form parsed */ /* Verify the device name , construct ses->local */ retval = get_sockaddr_ll(dev,&ses->local); if (retval < 0) poe_fatal(ses,"client_init_ses(2): " "Cannot create PF_PACKET socket for PPPoE discovery\n"); ses->state = PADS_CODE; create_msg(BCM_PPPOE_CLIENT_STATE_PADS); ses->sp.sa_family = AF_PPPOX; ses->sp.sa_protocol = PX_PROTO_OE; ses->sp.sa_addr.pppoe.sid = sid; memcpy(&ses->remote, &ses->local, sizeof(struct sockaddr_ll) ); for(; i < ETH_ALEN ; ++i ){ ses->sp.sa_addr.pppoe.remote[i] = addr[i]; ses->remote.sll_addr[i]=addr[i]; } memcpy(ses->sp.sa_addr.pppoe.dev, dev, IFNAMSIZ); } if( retval < 0 ) error("bad device name: %s",devnam); retval = bind( disc_sock , (struct sockaddr*)&ses->local, sizeof(struct sockaddr_ll)); if( retval < 0 ){ error("bind to PF_PACKET socket failed: %m"); } ses->fd = socket(AF_PPPOX,SOCK_STREAM,PX_PROTO_OE); if(ses->fd < 0) { poe_fatal(ses,"Failed to create PPPoE socket: %m"); } ses->init_disc = std_init_disc; ses->rcv_pado = std_rcv_pado; ses->rcv_pads = std_rcv_pads; ses->rcv_padt = std_rcv_padt; /* this should be filter overridable */ ses->retries = 10; return ses->fd; }
static int relay_rcv_pads(struct session* ses, struct pppoe_packet *p_in, struct pppoe_packet **p_out){ struct pppoe_con *pc; // char tag_buf[32]; struct pppoe_tag *tag = p_in->tags[TAG_RELAY_SID]; struct sockaddr_pppox sp_cl= { AF_PPPOX, PX_PROTO_OE, {{ p_in->hdr->sid, {0,},{0,}}}}; struct sockaddr_pppox sp_sv= { AF_PPPOX, PX_PROTO_OE, {{ p_in->hdr->sid, {0,},{0,}}}}; int ret; if( !tag ) return 0; pc = get_con(ntohs(tag->tag_len),tag->tag_data); if( !pc ) return 0; if(!pc->connected){ pc->sv_sock = socket( AF_PPPOX, SOCK_DGRAM, PX_PROTO_OE); if( pc->sv_sock < 0){ poe_fatal(ses,"Cannot open PPPoE socket: %i",errno); } pc->cl_sock = socket( AF_PPPOX, SOCK_DGRAM, PX_PROTO_OE); if( pc->cl_sock < 0){ poe_fatal(ses,"Cannot open PPPoE socket: %i",errno); } memcpy( sp_sv.sa_addr.pppoe.dev, ses->fwd_name, IFNAMSIZ); memcpy( sp_sv.sa_addr.pppoe.remote, pc->server, ETH_ALEN); ret = connect( pc->sv_sock, (struct sockaddr*)&sp_sv, sizeof(struct sockaddr_pppox)); if( ret < 0){ poe_fatal(ses,"Cannot connect PPPoE socket: %i",errno); } memcpy( sp_cl.sa_addr.pppoe.dev, ses->name, IFNAMSIZ); memcpy( sp_cl.sa_addr.pppoe.remote, pc->client, ETH_ALEN); ret = connect( pc->cl_sock, (struct sockaddr*)&sp_cl, sizeof(struct sockaddr_pppox)); if( ret < 0){ poe_fatal(ses,"Cannot connect PPPoE socket: %i",errno); } ret = ioctl( pc->sv_sock, PPPOEIOCSFWD, &sp_cl); if( ret < 0){ poe_fatal(ses,"Cannot set forwarding on PPPoE socket: %i",errno); } ret = ioctl( pc->cl_sock, PPPOEIOCSFWD, &sp_sv); if( ret < 0){ poe_fatal(ses,"Cannot set forwarding on PPPoE socket: %i",errno); } pc->connected = 1; } poe_info(ses,"PPPoE relay for %E established to %E (sid=%04x)\n", pc->client,pc->server, p_in->hdr->sid); return relay_rcv_pkt(ses,p_in,p_out); }