initial converion of liran's "Practical VPNs" to docbook
[l2tpns.git] / radius.c
index 6cb9e16..cbfcb14 100644 (file)
--- a/radius.c
+++ b/radius.c
@@ -1,6 +1,6 @@
 // L2TPNS Radius Stuff
 
-char const *cvs_id_radius = "$Id: radius.c,v 1.47 2005/12/19 06:18:13 bodea Exp $";
+char const *cvs_id_radius = "$Id: radius.c,v 1.49 2006/04/13 11:14:35 bodea Exp $";
 
 #include <time.h>
 #include <stdio.h>
@@ -158,7 +158,7 @@ void radiussend(uint16_t r, uint8_t state)
                if (s)
                {
                        if (state == RADIUSAUTH)
-                               sessionshutdown(s, "RADIUS timeout.", 3, 0);
+                               sessionshutdown(s, "RADIUS timeout.", CDN_ADMIN_DISC, TERM_REAUTHENTICATION_FAILURE);
                        else
                        {
                                LOG(1, s, session[s].tunnel, "RADIUS timeout, but in state %s so don't timeout session\n",
@@ -248,8 +248,8 @@ void radiussend(uint16_t r, uint8_t state)
                        p += p[1];
                }
        }
-       else if (state == RADIUSSTART || state == RADIUSSTOP || state == RADIUSINTERIM)
-       {                       // accounting
+       else // accounting
+       {
                *p = 40;        // accounting type
                p[1] = 6;
                *(uint32_t *) (p + 2) = htonl(state - RADIUSSTART + 1); // start=1, stop=2, interim=3
@@ -304,6 +304,24 @@ void radiussend(uint16_t r, uint8_t state)
                                p[1] = 6;
                                *(uint32_t *) (p + 2) = htonl(session[s].cout_wrap);
                                p += p[1];
+
+                               if (state == RADIUSSTOP && radius[r].term_cause)
+                               {
+                                       *p = 49; // acct-terminate-cause
+                                       p[1] = 6;
+                                       *(uint32_t *) (p + 2) = htonl(radius[r].term_cause);
+                                       p += p[1];
+
+                                       if (radius[r].term_msg)
+                                       {
+                                               *p = 26;                                // vendor-specific
+                                               *(uint32_t *) (p + 2) = htonl(9);       // Cisco
+                                               p[6] = 1;                               // Cisco-AVPair
+                                               p[7] = 2 + sprintf((char *) p + 8, "disc-cause-ext=%s", radius[r].term_msg);
+                                               p[1] = p[7] + 6;
+                                               p += p[1];
+                                       }
+                               }
                        }
 
                        {
@@ -785,7 +803,7 @@ void radiusretry(uint16_t r)
 
 extern int daefd;
 
-void processdae(uint8_t *buf, int len, struct sockaddr_in *addr, int alen)
+void processdae(uint8_t *buf, int len, struct sockaddr_in *addr, int alen, struct in_addr *local)
 {
        int i, r_code, r_id, length, attribute_length;
        uint8_t *packet, attribute;
@@ -994,7 +1012,7 @@ void processdae(uint8_t *buf, int len, struct sockaddr_in *addr, int alen)
                LOG(3, s, t, "    DAE Disconnect %d (%s)\n", s, session[s].user);
                r_code = DisconnectACK;
 
-               sessionshutdown(s, "Requested by PoD", 3, 0); // disconnect session
+               sessionshutdown(s, "Requested by PoD", CDN_ADMIN_DISC, TERM_ADMIN_RESET); // disconnect session
                break;
 
        case CoARequest: // Change of Authorization
@@ -1063,6 +1081,6 @@ void processdae(uint8_t *buf, int len, struct sockaddr_in *addr, int alen)
        LOG(3, 0, 0, "Sending DAE %s, id=%d\n", radius_code(r_code), r_id);
 
        // send DAE response
-       if (sendto(daefd, buf, len, MSG_DONTWAIT | MSG_NOSIGNAL, (struct sockaddr *) addr, alen) < 0)
+       if (sendtofrom(daefd, buf, len, MSG_DONTWAIT | MSG_NOSIGNAL, (struct sockaddr *) addr, alen, local) < 0)
                LOG(0, 0, 0, "Error sending DAE response packet: %s\n", strerror(errno));
 }