Don't call inet_ntop() for IP addresses by default. It's not
authoraland <aland>
Thu, 8 Sep 2005 20:58:50 +0000 (20:58 +0000)
committeraland <aland>
Thu, 8 Sep 2005 20:58:50 +0000 (20:58 +0000)
done that often anyways, and it has significant overhead.

Instead, print the data as appropriate, IF it's needed for
regex stuff, which is the only need for IP addresses as strings.

src/lib/print.c
src/main/valuepair.c
src/modules/rlm_attr_filter/rlm_attr_filter.c
src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c
src/modules/rlm_preprocess/rlm_preprocess.c

index d31581a..3cedc00 100644 (file)
@@ -171,11 +171,8 @@ int vp_prints_value(char * out, int outlen, VALUE_PAIR *vp, int delimitst)
                        a = buf;
                        break;
                case PW_TYPE_IPADDR:
-                       if (vp->vp_strvalue[0])
-                               a = (char *)vp->vp_strvalue;
-                       else
-                               a = inet_ntop(AF_INET, &(vp->lvalue),
-                                             buf, sizeof(buf));
+                       a = inet_ntop(AF_INET, &(vp->lvalue),
+                                     buf, sizeof(buf));
                        break;
                case PW_TYPE_ABINARY:
 #ifdef ASCEND_BINARY
index 1c4051b..ed75935 100644 (file)
@@ -367,6 +367,13 @@ int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check, VALUE_PAIR **r
                                int i;
                                regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];
 
+                               if ((auth_item->type == PW_TYPE_IPADDR) &&
+                                   (auth_item->vp_strvalue[0] == '\0')) {
+                                 inet_ntop(AF_INET, &(auth_item->lvalue),
+                                           auth_item->vp_strvalue,
+                                           sizeof(auth_item->vp_strvalue));
+                               }
+
                                /*
                                 *      Include substring matches.
                                 */
@@ -432,6 +439,13 @@ int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check, VALUE_PAIR **r
                                break;
 
                        case T_OP_REG_NE:
+                               if ((auth_item->type == PW_TYPE_IPADDR) &&
+                                   (auth_item->vp_strvalue[0] == '\0')) {
+                                 inet_ntop(AF_INET, &(auth_item->lvalue),
+                                           auth_item->vp_strvalue,
+                                           sizeof(auth_item->vp_strvalue));
+                               }
+
                                regcomp(&reg, (char *)check_item->vp_strvalue, REG_EXTENDED|REG_NOSUB);
                                compare = regexec(&reg, (char *)auth_item->vp_strvalue,
                                                0, NULL, 0);
index 3630bfc..cf38015 100644 (file)
@@ -116,6 +116,13 @@ static int check_pair(VALUE_PAIR *check_item, VALUE_PAIR *reply_item,
                    break;
 #ifdef HAVE_REGEX_H
                case T_OP_REG_EQ:
+                 if ((reply_item->type == PW_TYPE_IPADDR) &&
+                     (reply_item->vp_strvalue[0] == '\0')) {
+                         inet_ntop(AF_INET, &(reply_item->lvalue),
+                                   reply_item->vp_strvalue,
+                                   sizeof(reply_item->vp_strvalue));
+                 }
+
                    regcomp(&reg, (char *)check_item->vp_strvalue, REG_EXTENDED);
                    comp = regexec(&reg, (char *)reply_item->vp_strvalue,
                                      0, NULL, 0);
@@ -128,6 +135,13 @@ static int check_pair(VALUE_PAIR *check_item, VALUE_PAIR *reply_item,
                    break;
 
                case T_OP_REG_NE:
+                 if ((reply_item->type == PW_TYPE_IPADDR) &&
+                     (reply_item->vp_strvalue[0] == '\0')) {
+                         inet_ntop(AF_INET, &(reply_item->lvalue),
+                                   reply_item->vp_strvalue,
+                                   sizeof(reply_item->vp_strvalue));
+                 }
+
                    regcomp(&reg, (char *)check_item->vp_strvalue, REG_EXTENDED);
                    comp = regexec(&reg, (char *)reply_item->vp_strvalue,
                                      0, NULL, 0);
index b68fb59..5959d15 100644 (file)
@@ -287,6 +287,14 @@ do_again:
                        DEBUG2("rlm_attr_rewrite: regcomp() returned error: %s",err_msg);
                        return ret;
                }
+               
+               if ((attr_vp->type == PW_TYPE_IPADDR) &&
+                   (attr_vp->vp_strvalue[0] == '\0')) {
+                 inet_ntop(AF_INET, &(attr_vp->lvalue),
+                           attr_vp->vp_strvalue,
+                           sizeof(attr_vp->vp_strvalue));
+               }
+
                ptr = new_str;
                ptr2 = attr_vp->vp_strvalue;
                counter = 0;
index 54f972d..badfc97 100644 (file)
@@ -402,9 +402,6 @@ static int add_nas_attr(REQUEST *request)
                                radlog(L_ERR, "No memory");
                                return -1;
                        }
-                       
-                       ip_ntoh(&request->packet->src_ipaddr,
-                               nas->vp_strvalue, sizeof(nas->vp_strvalue));
                        nas->lvalue = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr;
                        pairadd(&request->packet->vps, nas);
                }