/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

* plugins.d/mandos-client.c (good_interface): Use SIOCGIFFLAGS instead
                                              of reading
                                              /sys/class/net/*/flags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1085
1085
  errno = old_errno;
1086
1086
}
1087
1087
 
1088
 
/* 
1089
 
 * This function determines if a directory entry in /sys/class/net
1090
 
 * corresponds to an acceptable network device.
1091
 
 * (This function is passed to scandir(3) as a filter function.)
1092
 
 */
1093
 
int good_interface(const struct dirent *if_entry){
1094
 
  ssize_t ssret;
 
1088
bool get_flags(const char *ifname, struct ifreq *ifr){
1095
1089
  int ret;
1096
 
  if(if_entry->d_name[0] == '.'){
1097
 
    return 0;
1098
 
  }
 
1090
  
1099
1091
  int s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
1100
1092
  if(s < 0){
1101
1093
    perror_plus("socket");
1102
 
    return 0;
 
1094
    return false;
1103
1095
  }
1104
 
  struct ifreq ifr;
1105
 
  strcpy(ifr.ifr_name, if_entry->d_name);
1106
 
  ret = ioctl(s, SIOCGIFFLAGS, &ifr);
 
1096
  strcpy(ifr->ifr_name, ifname);
 
1097
  ret = ioctl(s, SIOCGIFFLAGS, ifr);
1107
1098
  if(ret == -1){
1108
1099
    if(debug){
1109
1100
      perror_plus("ioctl SIOCGIFFLAGS");
1110
1101
    }
1111
 
    return 0;
 
1102
    return false;
1112
1103
  }
 
1104
  return true;
 
1105
}
 
1106
 
 
1107
bool good_flags(const char *ifname, const struct ifreq *ifr){
 
1108
  
1113
1109
  /* Reject the loopback device */
1114
 
  if(ifr.ifr_flags & IFF_LOOPBACK){
 
1110
  if(ifr->ifr_flags & IFF_LOOPBACK){
1115
1111
    if(debug){
1116
1112
      fprintf(stderr, "Rejecting loopback interface \"%s\"\n",
1117
 
              if_entry->d_name);
 
1113
              ifname);
1118
1114
    }
1119
 
    return 0;
 
1115
    return false;
1120
1116
  }
1121
1117
  /* Accept point-to-point devices only if connect_to is specified */
1122
 
  if(connect_to != NULL and (ifr.ifr_flags & IFF_POINTOPOINT)){
 
1118
  if(connect_to != NULL and (ifr->ifr_flags & IFF_POINTOPOINT)){
1123
1119
    if(debug){
1124
1120
      fprintf(stderr, "Accepting point-to-point interface \"%s\"\n",
1125
 
              if_entry->d_name);
 
1121
              ifname);
1126
1122
    }
1127
 
    return 1;
 
1123
    return true;
1128
1124
  }
1129
1125
  /* Otherwise, reject non-broadcast-capable devices */
1130
 
  if(not (ifr.ifr_flags & IFF_BROADCAST)){
 
1126
  if(not (ifr->ifr_flags & IFF_BROADCAST)){
1131
1127
    if(debug){
1132
1128
      fprintf(stderr, "Rejecting non-broadcast interface \"%s\"\n",
1133
 
              if_entry->d_name);
 
1129
              ifname);
1134
1130
    }
1135
 
    return 0;
 
1131
    return false;
1136
1132
  }
1137
1133
  /* Reject non-ARP interfaces (including dummy interfaces) */
1138
 
  if(ifr.ifr_flags & IFF_NOARP){
 
1134
  if(ifr->ifr_flags & IFF_NOARP){
1139
1135
    if(debug){
1140
 
      fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n",
1141
 
              if_entry->d_name);
 
1136
      fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n", ifname);
1142
1137
    }
1143
 
    return 0;
 
1138
    return false;
1144
1139
  }
 
1140
  
1145
1141
  /* Accept this device */
1146
1142
  if(debug){
1147
 
    fprintf(stderr, "Interface \"%s\" is acceptable\n",
1148
 
            if_entry->d_name);
 
1143
    fprintf(stderr, "Interface \"%s\" is good\n", ifname);
 
1144
  }
 
1145
  return true;
 
1146
}
 
1147
 
 
1148
/* 
 
1149
 * This function determines if a directory entry in /sys/class/net
 
1150
 * corresponds to an acceptable network device.
 
1151
 * (This function is passed to scandir(3) as a filter function.)
 
1152
 */
 
1153
int good_interface(const struct dirent *if_entry){
 
1154
  int ret;
 
1155
  if(if_entry->d_name[0] == '.'){
 
1156
    return 0;
 
1157
  }
 
1158
  struct ifreq ifr;
 
1159
 
 
1160
  if(not get_flags(if_entry->d_name, &ifr)){
 
1161
    return 0;
 
1162
  }
 
1163
  
 
1164
  if(not good_flags(if_entry->d_name, &ifr)){
 
1165
    return 0;
1149
1166
  }
1150
1167
  return 1;
1151
1168
}