Radclient : received bad packet
I am new in freeradius. I am generating DM-request Package from Radius server side with below mention command Acct-Session-ID and NAS-IP_address taken as random value for testing: echo "User-Name=arv,Acct-Session-Id=12354679, NAS-IP_Address=1.1.1.1"| radclient 1.1.1.1:3799 disconnect testing123 code:: Attached with mail Error: radclient: received bad packet # What is causing this problem and how we can solve this problem?
On Oct 5, 2019, at 6:43 AM, Arvind Chauhan <abbey875@gmail.com> wrote:
I am new in freeradius. I am generating DM-request Package from Radius server side with below mention command Acct-Session-ID and NAS-IP_address taken as random value for testing: echo "User-Name=arv,Acct-Session-Id=12354679, NAS-IP_Address=1.1.1.1"| radclient 1.1.1.1:3799 disconnect testing123
code::
Attached with mail
Error:
radclient: received bad packet
# What is causing this problem and how we can solve this problem?
Print the actual error message: printf( "radclient: received bad packet: %s\n",strerror(errno)); This is wrong. You should use fr_strerror(), which returns a descriptive message. strerror() is for getting errors from system calls / system libraries. We use our own error wrapper. Alan DeKok.
with fr_strerror(), I m getting unknown error. radclient: received bad packet: (unknown error) Thanks, Arvind Chauhan On Sat, Oct 5, 2019 at 5:10 PM Alan DeKok <aland@deployingradius.com> wrote:
On Oct 5, 2019, at 6:43 AM, Arvind Chauhan <abbey875@gmail.com> wrote:
I am new in freeradius. I am generating DM-request Package from Radius server side with below mention command Acct-Session-ID and NAS-IP_address taken as random value for testing: echo "User-Name=arv,Acct-Session-Id=12354679, NAS-IP_Address=1.1.1.1"| radclient 1.1.1.1:3799 disconnect testing123
code::
Attached with mail
Error:
radclient: received bad packet
# What is causing this problem and how we can solve this problem?
Print the actual error message:
printf( "radclient: received bad packet: %s\n",strerror(errno));
This is wrong. You should use fr_strerror(), which returns a descriptive message. strerror() is for getting errors from system calls / system libraries. We use our own error wrapper.
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On Oct 6, 2019, at 4:49 AM, Arvind Chauhan <abbey875@gmail.com> wrote:
with fr_strerror(), I m getting unknown error. radclient: received bad packet: (unknown error)
Well, the radclient we ship works. Something else is going wrong, and you'll have to debug it. You have the source code, so you can use a debugger, or you can instrument the source code. Alan DeKok.
Arvind, You have this code: reply = fr_packet_list_recv(pl, &rdset); if (!reply) { printf( "radclient: received bad packet: %s\n",strerror(errno)); return -1; /* bad packet */ } Two things about it: On the freeradius library: packet.c:908 (fr_packet_list_recv) there are two possible reasons that the function will return NULL (your case). 1. pl OR rdset == NULL (packet.c: if (!pl || !set) return NULL;) 2. This doesn't hold (from packet.c): start = pl->last_recv; do ... } while (start != pl->last_recv); I would say that you have an issue with pl or rdset or pl->last_recv is different than what freeradius expect. NOTES: I would actually suggest replacing:
if ((bind(fd, (struct sockaddr *)&serveraddr, addrsize))<0)
by this:
if ((bind(fd, (struct sockaddr *)&serveraddr, addrsize)) == -1)
From bind(2) (POSIX.1)
RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately. Orestes
Thanks Orestes Leal Rodríguez & Alan dekok for your help. Now I m able to receive a packet and respond back successfully. But now i want to read attribute value pairs from CoA and DM-request. What I know is whatever attribute that we get needs to be converted to VALUE_PAIR and then with attribute name we can read it. I want to know that what api's can be used to convert attribute to VALUE_PAIR and then read it. I have pasted my code. while(1) { max_fd = fd + 1; fd_set rdset; FD_ZERO(&rdset); FD_SET(fd, &rdset); retval = select(max_fd, &rdset, NULL, NULL, &tv); if (retval == -1) perror("select()"); else if (retval){ syslog(LOG_INFO,"Radius:: Data is available now.\n"); if(FD_ISSET(fd, &rdset)) { RADIUS_PACKET *packet = rad_recv(fd, 0); char src_addr[INET_ADDRSTRLEN + 1] = {'\0'}; char dst_addr[INET_ADDRSTRLEN + 1] = {'\0'}; int sport = 0; int dport = 0; inet_ntop(AF_INET, &packet->src_ipaddr.ipaddr, src_addr, INET_ADDRSTRLEN); syslog(LOG_INFO,"Radius:: src_addr : %s\n", src_addr); inet_ntop(AF_INET,&packet->dst_ipaddr.ipaddr, dst_addr, INET_ADDRSTRLEN); syslog(LOG_INFO,"Radius:: dst_addr : %s\n", dst_addr); syslog(LOG_INFO,"Radius:: src_port : %d\n", packet->src_port); syslog(LOG_INFO,"Radius:: dst_port : %d\n", packet->dst_port); sport = packet->src_port; dport = packet->dst_port; syslog(LOG_INFO,"Radius:: id: %d\n", packet->id); syslog(LOG_INFO,"Radius:: code: %d\n", packet->code); syslog(LOG_INFO,"Radius:: hash: %d\n", packet->hash); int i = 0; for(i = 0; i < AUTH_VECTOR_LEN; i++) syslog(LOG_INFO,"Radius:: vector: 0x%x\n ", packet->vector[i]); hdr = (radius_packet_t *)packet->data; ptr = hdr->data; packet_length = packet->data_len - AUTH_HDR_LEN; if(rad_verify(packet,NULL, m_externalAuthConfig.m_radiusConfig.m_shareSecret) == -1) { syslog(LOG_INFO,"Radius:: rad_verify failed : %s \n", fr_strerror()); } else syslog(LOG_INFO,"Radius:: Rad_verify successful\n"); if(rad_decode(packet,NULL, m_externalAuthConfig.m_radiusConfig.m_shareSecret) == -1) { syslog(LOG_INFO,"Radius:: rad_decode failed : %s\n", fr_strerror()); } else syslog(LOG_INFO,"Radius:: rad_decode successful \n"); RADIUS_PACKET *reply = rad_alloc_reply(packet); switch(packet->code) { case PW_DISCONNECT_REQUEST: syslog(LOG_INFO,"Radius:: PW_DISCONNECT_REQUEST "); syslog(LOG_INFO,"Radius:: Loggedin session user ::%s ", radiususerSessionInfo.userName); if(strstr(radiususerSessionInfo.userName,"arv")) { syslog(LOG_INFO,"Radius:: Returning 1 to django"); flag_logout = 1; kill(getpid(),SIGUSR1); reply->code = htonl(41); } else reply->code = htonl(40); memset(&radiususerSessionInfo,0,sizeof(radiususerSessionInfo)); break; case PW_COA_REQUEST: syslog(LOG_INFO,"Radius:: PW_COA_REQUEST "); break; default: syslog(LOG_INFO,"Radius:: Request recieved is other them COA and DM"); } if(rad_send(reply, NULL, m_externalAuthConfig.m_radiusConfig.m_shareSecret) == -1) { syslog(LOG_INFO,"Radius:: rad_send failed : %s", fr_strerror()); } else syslog(LOG_INFO,"Radius:: Rad_send successful"); } else syslog(LOG_INFO,"Radius:: FD_ISSET Failed"); } } } Regards, Arvind Chauhan On Sun, Oct 6, 2019 at 10:24 PM Orestes Leal Rodríguez < olealrd1981@gmail.com> wrote:
Arvind,
You have this code:
reply = fr_packet_list_recv(pl, &rdset); if (!reply) { printf( "radclient: received bad packet: %s\n",strerror(errno)); return -1; /* bad packet */ }
Two things about it:
On the freeradius library: packet.c:908 (fr_packet_list_recv) there are two possible reasons that the function will return NULL (your case).
1. pl OR rdset == NULL (packet.c: if (!pl || !set) return NULL;)
2. This doesn't hold (from packet.c):
start = pl->last_recv; do ... } while (start != pl->last_recv);
I would say that you have an issue with pl or rdset or pl->last_recv is different than what freeradius expect.
NOTES:
I would actually suggest replacing:
if ((bind(fd, (struct sockaddr *)&serveraddr, addrsize))<0)
by this:
if ((bind(fd, (struct sockaddr *)&serveraddr, addrsize)) == -1)
From bind(2) (POSIX.1)
RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
Orestes - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On Oct 18, 2019, at 3:25 AM, Arvind Chauhan <abbey875@gmail.com> wrote:
Thanks Orestes Leal Rodríguez & Alan dekok for your help. Now I m able to receive a packet and respond back successfully. But now i want to read attribute value pairs from CoA and DM-request. What I know is whatever attribute that we get needs to be converted to VALUE_PAIR and then with attribute name we can read it. I want to know that what api's can be used to convert attribute to VALUE_PAIR and then read it.
Read radclient.c. *All* of the APIs are used there. There is also extensive API documentation on the web site: https://doc.freeradius.org Alan DeKok.
Arvind, take a look at https://doc.freeradius.org/pair_8h_source.html Orestes On 10/18/19, Alan DeKok <aland@deployingradius.com> wrote:
On Oct 18, 2019, at 3:25 AM, Arvind Chauhan <abbey875@gmail.com> wrote:
Thanks Orestes Leal Rodríguez & Alan dekok for your help. Now I m able to receive a packet and respond back successfully. But now i want to read attribute value pairs from CoA and DM-request. What I know is whatever attribute that we get needs to be converted to VALUE_PAIR and then with attribute name we can read it. I want to know that what api's can be used to convert attribute to VALUE_PAIR and then read it.
Read radclient.c. *All* of the APIs are used there. There is also extensive API documentation on the web site:
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
participants (3)
-
Alan DeKok -
Arvind Chauhan -
Orestes Leal Rodríguez