nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 2002, 2008, 2009, 2011, 2012 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or (at 00008 // your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #include <arpa/inet.h> 00020 #include <netinet/in.h> 00021 00022 #include <lib/net_utils.h> 00023 #include <lib/space/netmasks/slurp.h> 00024 00025 #include <nis-util-networks/space/networks/slurp/check.h> 00026 00027 00028 space_networks_slurp_check::~space_networks_slurp_check() 00029 { 00030 } 00031 00032 00033 space_networks_slurp_check::space_networks_slurp_check( 00034 const rcstring &a_filename, 00035 const space_netmasks_slurp::pointer &a_netmasks 00036 ) : 00037 space_networks_slurp(a_filename), 00038 netmasks(a_netmasks) 00039 { 00040 } 00041 00042 00043 #define LSB(x) ((x) & -(x)) 00044 00045 00046 void 00047 space_networks_slurp_check::process(const record::pointer &rp) 00048 { 00049 // 00050 // Do all the usual processing. 00051 // 00052 space_networks_slurp::process(rp); 00053 00054 // 00055 // Make sure each network has a corresponding netmask. 00056 // 00057 if (!netmasks->query_by_address(rp->get_number())) 00058 { 00059 unsigned long nnum = rp->get_number_binary(); 00060 unsigned long mask_by_class = network_mask_from_number(nnum); 00061 if (nnum & ~mask_by_class) 00062 { 00063 // 00064 // Some networks absolutely require a netmask entry, because 00065 // the default mask will not suffice. 00066 // 00067 unsigned long suggest = 0xFFFFFFFFuL ^ (LSB(nnum) - 1); 00068 rcstring suggest_str = string_from_network_number(suggest); 00069 error 00070 ( 00071 rp->get_source_location(), 00072 "netmask for %s not present in netmasks map, " 00073 "suggest %s %s be inserted", 00074 rp->get_number().quote_c().c_str(), 00075 suggest_str.quote_c().c_str(), 00076 (suggest < 0xFFFFFFFCuL ? "or wider" : "") 00077 ); 00078 } 00079 else 00080 { 00081 rcstring suggest_str = string_from_network_number(mask_by_class); 00082 error 00083 ( 00084 rp->get_source_location(), 00085 "netmask for %s not present in netmasks map, " 00086 "suggest %s be inserted", 00087 rp->get_number().quote_c().c_str(), 00088 suggest_str.quote_c().c_str() 00089 ); 00090 } 00091 } 00092 } 00093 00094 00095 // vim: set ts=8 sw=4 et :