Fix whitespace errors in ppp.c and radius.c
[l2tpns.git] / radius.c
index 93a1cde..faf1791 100644 (file)
--- a/radius.c
+++ b/radius.c
@@ -348,7 +348,7 @@ void radiussend(uint16_t r, uint8_t state)
 
                                if (state == RADIUSSTOP && radius[r].term_cause)
                                {
-                                       *p = 49; // acct-terminate-cause
+                                       *p = 49; // acct-terminate-cause
                                        p[1] = 6;
                                        *(uint32_t *) (p + 2) = htonl(radius[r].term_cause);
                                        p += p[1];
@@ -379,12 +379,12 @@ void radiussend(uint16_t r, uint8_t state)
                *(uint32_t *) (p + 2) = htonl(s);
                p += p[1];
 
-               *p = 6;         // Service-Type
+               *p = 6;         // Service-Type
                p[1] = 6;
                *(uint32_t *) (p + 2) = htonl((state == RADIUSJUSTAUTH ? 8 : 2)); // Authenticate only or Framed-User respectevily
                p += p[1];
                   
-               *p = 7;         // Framed-Protocol
+               *p = 7;         // Framed-Protocol
                p[1] = htonl((state == RADIUSJUSTAUTH ? 0 : 6));
                *(uint32_t *) (p + 2) = htonl((state == RADIUSJUSTAUTH ? 0 : 1)); // PPP
                p += p[1];
@@ -402,21 +402,11 @@ void radiussend(uint16_t r, uint8_t state)
                        int r;
                        for (r = 0; s && r < MAXROUTE && session[s].route[r].ip; r++)
                        {
-                               int width = 32;
-                               if (session[s].route[r].mask)
-                               {
-                                   int mask = session[s].route[r].mask;
-                                   while (!(mask & 1))
-                                   {
-                                       width--;
-                                       mask >>= 1;
-                                   }
-                               }
-
                                *p = 22;        // Framed-Route
                                p[1] = sprintf((char *) p + 2, "%s/%d %s 1",
                                        fmtaddr(htonl(session[s].route[r].ip), 0),
-                                       width, fmtaddr(htonl(session[s].ip), 1)) + 2;
+                                       session[s].route[r].prefixlen,
+                                       fmtaddr(htonl(session[s].ip), 1)) + 2;
 
                                p += p[1];
                        }
@@ -496,7 +486,7 @@ static void handle_avpair(sessionidt s, uint8_t *avp, int len)
        }
        else
        {
-               value = tmp;
+               value = tmp;
                len = 0;
        }
 
@@ -656,7 +646,7 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                                else if (vendor == 529 && attrib >= 135 && attrib <= 136) // Ascend
                                                {
                                                        // handle old-format ascend DNS attributes below
-                                                       p += 6;
+                                                       p += 6;
                                                }
                                                else
                                                {
@@ -668,7 +658,7 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                        if (*p == 8)
                                        {
                                                // Framed-IP-Address
-                                               if (p[1] < 6) continue;
+                                               if (p[1] < 6) continue;
                                                session[s].ip = ntohl(*(uint32_t *) (p + 2));
                                                session[s].ip_pool_index = -1;
                                                LOG(3, s, session[s].tunnel, "   Radius reply contains IP address %s\n",
@@ -680,7 +670,7 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                        else if (*p == 135)
                                        {
                                                // DNS address
-                                               if (p[1] < 6) continue;
+                                               if (p[1] < 6) continue;
                                                session[s].dns1 = ntohl(*(uint32_t *) (p + 2));
                                                LOG(3, s, session[s].tunnel, "   Radius reply contains primary DNS address %s\n",
                                                        fmtaddr(htonl(session[s].dns1), 0));
@@ -688,7 +678,7 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                        else if (*p == 136)
                                        {
                                                // DNS address
-                                               if (p[1] < 6) continue;
+                                               if (p[1] < 6) continue;
                                                session[s].dns2 = ntohl(*(uint32_t *) (p + 2));
                                                LOG(3, s, session[s].tunnel, "   Radius reply contains secondary DNS address %s\n",
                                                        fmtaddr(htonl(session[s].dns2), 0));
@@ -696,7 +686,7 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                        else if (*p == 22)
                                        {
                                                // Framed-Route
-                                               in_addr_t ip = 0, mask = 0;
+                                               in_addr_t ip = 0;
                                                uint8_t u = 0;
                                                uint8_t bits = 0;
                                                uint8_t *n = p + 2;
@@ -718,14 +708,13 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                                        n++;
                                                        while (n < e && isdigit(*n))
                                                                bits = bits * 10 + *n++ - '0';
-                                                       mask = (( -1) << (32 - bits));
                                                }
                                                else if ((ip >> 24) < 128)
-                                                       mask = 0xFF0000;
+                                                       bits = 8;
                                                else if ((ip >> 24) < 192)
-                                                       mask = 0xFFFF0000;
+                                                       bits = 16;
                                                else
-                                                       mask = 0xFFFFFF00;
+                                                       bits = 24;
 
                                                if (routes == MAXROUTE)
                                                {
@@ -733,18 +722,18 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                                }
                                                else if (ip)
                                                {
-                                                       LOG(3, s, session[s].tunnel, "   Radius reply contains route for %s/%s\n",
-                                                               fmtaddr(htonl(ip), 0), fmtaddr(htonl(mask), 1));
+                                                       LOG(3, s, session[s].tunnel, "   Radius reply contains route for %s/%d\n",
+                                                               fmtaddr(htonl(ip), 0), bits);
                                                        
                                                        session[s].route[routes].ip = ip;
-                                                       session[s].route[routes].mask = mask;
+                                                       session[s].route[routes].prefixlen = bits;
                                                        routes++;
                                                }
                                        }
                                        else if (*p == 11)
                                        {
-                                               // Filter-Id
-                                               char *filter = (char *) p + 2;
+                                               // Filter-Id
+                                               char *filter = (char *) p + 2;
                                                int l = p[1] - 2;
                                                char *suffix;
                                                int f;
@@ -780,17 +769,17 @@ void processrad(uint8_t *buf, int len, char socket_index)
                                        }
                                        else if (*p == 27)
                                        {
-                                               // Session-Timeout
-                                               if (p[1] < 6) continue;
+                                               // Session-Timeout
+                                               if (p[1] < 6) continue;
                                                session[s].session_timeout = ntohl(*(uint32_t *)(p + 2));
                                                LOG(3, s, session[s].tunnel, "   Radius reply contains Session-Timeout = %u\n", session[s].session_timeout);
                                                if(!session[s].session_timeout && config->kill_timedout_sessions)
-                                                        sessionshutdown(s, "Session timeout is zero", CDN_ADMIN_DISC, 0);
+                                                       sessionshutdown(s, "Session timeout is zero", CDN_ADMIN_DISC, 0);
                                        }
                                        else if (*p == 28)
                                        {
-                                               // Idle-Timeout
-                                               if (p[1] < 6) continue;
+                                               // Idle-Timeout
+                                               if (p[1] < 6) continue;
                                                session[s].idle_timeout = ntohl(*(uint32_t *)(p + 2));
                                                LOG(3, s, session[s].tunnel, "   Radius reply contains Idle-Timeout = %u\n", session[s].idle_timeout);
                                        }
@@ -1105,7 +1094,7 @@ void processdae(uint8_t *buf, int len, struct sockaddr_in *addr, int alen, struc
        case CoARequest: // Change of Authorization
                if (error)
                {
-                       r_code = CoANAK;
+                       r_code = CoANAK;
                        break;
                }