LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-24-2013, 02:04 AM   #1
nazekimi
LQ Newbie
 
Registered: Jun 2011
Posts: 6

Rep: Reputation: Disabled
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
 
Old 10-25-2013, 04:04 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,893

Rep: Reputation: 163Reputation: 163
The 1 bits of correct netmask should be continue.
 
Old 10-28-2013, 01:36 AM   #3
nazekimi
LQ Newbie
 
Registered: Jun 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by nini09 View Post
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?
 
Old 10-28-2013, 10:13 AM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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.
 
Old 10-28-2013, 03:19 PM   #5
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,893

Rep: Reputation: 163Reputation: 163
No, you can't ignore the rule except your own kernel.
 
Old 10-30-2013, 04:57 AM   #6
nazekimi
LQ Newbie
 
Registered: Jun 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by sag47 View Post
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.
 
Old 10-30-2013, 08:03 AM   #7
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Rep: Reputation: 5
slightly offtopic:

why is this netmask invalid?

TIA
 
Old 10-30-2013, 11:34 AM   #8
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by sree_ec View Post
why is this netmask invalid?
Quote:
Originally Posted by nazekimi View Post
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.
Old 10-30-2013, 01:59 PM   #9
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Rep: Reputation: 5
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

Last edited by sree_ec; 10-30-2013 at 03:14 PM.
 
Old 10-30-2013, 02:01 PM   #10
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by sree_ec View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] RTNETLINK answers: File exists - Error when doing ifup on alias (eth1:1) on RHEL5 MensaWater Linux - Networking 17 04-12-2015 08:32 AM
ifup: couldn't read interfaces file "/etc/network/interfaces" debian lenny lorimer73 Linux - Networking 1 08-24-2010 04:47 PM
OpenVPN - server directive network/netmask combination is invalid anthonysaulnier Linux - Networking 4 11-18-2008 10:41 PM
ifup cant read network interfaces flebber Debian 3 03-13-2006 05:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration