Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
![Reply](https://www.linuxquestions.org/questions/images/buttons/reply.gif) |
10-24-2013, 02:04 AM
|
#1
|
LQ Newbie
Registered: Jun 2011
Posts: 6
Rep: ![Reputation: Disabled](https://www.linuxquestions.org/questions/images/reputation/reputation_off.gif)
|
What does ifup do when “interfaces” file has an invalid netmask?
The interfaces file looks like below:
Code:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.130
netmask 250.255.255.0
gateway 192.168.0.254
As you can see the netmask address is sort of invalid. (250 instead of 255) The problem is when I use the following code to get the current IP address and netmask:
Code:
ioctl(iSock, SIOCGIFADDR, &stIFReq);
ioctl(iSock, SIOCGIFNETMASK, &stIFReq);
It always returns " 72,0,xxx,xxx" (the last two octets seem to change depending on the device, but always constant for the same device) on both ioctl functions. I wonder if this is some sort of error code or bug during ifup. I would like to know what type of checking ifup does on netmasks/ip addresses and what does it do if the address is judged as invalid.
What steps can be taken to recover from a "bad" netmask address setting and maybe run a default "255.255.255.0" address?
Thanks.
Additional info:
Linux version 2.6.35.3, running on an ARM cpu embedded system
BusyBox v1.18.5
[ifup] is not a script but a C program on the system
|
|
|
10-25-2013, 04:04 PM
|
#2
|
Senior Member
Registered: Apr 2009
Posts: 1,893
Rep: ![Reputation: 163](https://www.linuxquestions.org/questions/images/reputation/reputation_pos.gif)
|
The 1 bits of correct netmask should be continue.
|
|
|
10-28-2013, 01:36 AM
|
#3
|
LQ Newbie
Registered: Jun 2011
Posts: 6
Original Poster
Rep: ![Reputation: Disabled](https://www.linuxquestions.org/questions/images/reputation/reputation_off.gif)
|
Quote:
Originally Posted by nini09
The 1 bits of correct netmask should be continue.
|
Is there anyway for ifup or interfaces to ignore this rule? What steps should I take on boot-up to recover from such a situation?
|
|
|
10-28-2013, 10:13 AM
|
#4
|
Senior Member
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
|
You can run a script on startup that checks the current netmask and if it is not valid then set a default... See man 5 crontab and look at the @reboot alias.
Here's a python function for checking a single octet of a netmask... I don't have time to write the rest of the script to check a whole netmask but I'd recommend using it in a class with recursion to do it.
Code:
def check(partial_mask):
x=0
while True:
if x==partial_mask:
return partial_mask
elif (x==255 and x!=partial_mask):
return None
x=x>>1|128
The core of your question *should be* is why does your netmask get arbitrarily set to something not proper? You should fix the root of the problem rather than create patch work around temporarily fixing it. Duct tape will only work for so long.
Last edited by sag47; 10-28-2013 at 02:13 PM.
|
|
|
10-28-2013, 03:19 PM
|
#5
|
Senior Member
Registered: Apr 2009
Posts: 1,893
Rep: ![Reputation: 163](https://www.linuxquestions.org/questions/images/reputation/reputation_pos.gif)
|
No, you can't ignore the rule except your own kernel.
|
|
|
10-30-2013, 04:57 AM
|
#6
|
LQ Newbie
Registered: Jun 2011
Posts: 6
Original Poster
Rep: ![Reputation: Disabled](https://www.linuxquestions.org/questions/images/reputation/reputation_off.gif)
|
Quote:
Originally Posted by sag47
You can run a script on startup that checks the current netmask and if it is not valid then set a default... See man 5 crontab and look at the @reboot alias.
Here's a python function for checking a single octet of a netmask... I don't have time to write the rest of the script to check a whole netmask but I'd recommend using it in a class with recursion to do it.
Code:
def check(partial_mask):
x=0
while True:
if x==partial_mask:
return partial_mask
elif (x==255 and x!=partial_mask):
return None
x=x>>1|128
The core of your question *should be* is why does your netmask get arbitrarily set to something not proper? You should fix the root of the problem rather than create patch work around temporarily fixing it. Duct tape will only work for so long.
|
Thank you for your suggestion. I guess configuring it manually is better than just feeding ifup the interfaces file.
As per the title of my post, I really was looking for reasons why ifup does what it does on such address settings. Perhaps my English is hard to understand.
Anyway, since there are really no clear information on that direction, as of now, I'll just go ahead and apply that duct-tape.
|
|
|
10-30-2013, 08:03 AM
|
#7
|
Member
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76
Rep:
|
slightly offtopic:
why is this netmask invalid?
TIA
|
|
|
10-30-2013, 11:34 AM
|
#8
|
Senior Member
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
|
Quote:
Originally Posted by sree_ec
why is this netmask invalid?
|
Quote:
Originally Posted by nazekimi
Code:
netmask 250.255.255.0
|
Google search. The short answer is a netmask designates how many bits in an ip address are for network identification and how many bits in an ip address are for host identification.
Essentially the IP address is split into two halves... e.g. 255.255.0.0
Code:
11111111.11111111.00000000.00000000
Since there can only be two halves (network identification or host identification) then 250.255.255.0 breaks that standard because there can't be zeroes mixed into the network identification. The bits identifying network must be contiguous 1's.
Not valid: 250.255.255.0 (converted into binary below to emphasize point)
Code:
11111010.11111111.11111111.00000000
|
|
1 members found this post helpful.
|
10-30-2013, 01:59 PM
|
#9
|
Member
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76
Rep:
|
I never thought network Id is a part of netmask in the sense you have just explained. What my understanding was networkId=Ipaddress (logical AND) netmask.
I never thought it exists as a part of netamsk and should contain only 1s.
Thanks for explaining ![Smilie](https://www.linuxquestions.org/questions/images/smilies/smile.gif)
Last edited by sree_ec; 10-30-2013 at 03:14 PM.
|
|
|
10-30-2013, 02:01 PM
|
#10
|
Senior Member
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
|
Quote:
Originally Posted by sree_ec
I never thought network Id is a part of netmask in the sense you have just explained. What my understanding was networkId=Ipaddress (logical AND) netmask.
|
You're correct. Network ID == IPADDRESS & NETMASK.
So if netmask doesn't contain all 1's from left to right contiguously then you'll get weird network ID's from some IP addresses but not others. That's why you can do the logical AND because of the format of the netmask.
Last edited by sag47; 10-30-2013 at 02:03 PM.
|
|
|
All times are GMT -5. The time now is 07:53 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|