Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-08-20 Thread John Baldwin
On Friday, August 17, 2012 6:58:58 pm Peter Jeremy wrote:
> On 2012-Aug-17 11:48:17 -0400, John Baldwin  wrote:
> >Hmm, I think I see the issue.  It doesn't export the existing lease info to
> >the script when running the FAIL action.  I just tested this change and it
> >removed the old IP on my laptop when I tested it just now.
> 
> I did some investigating during the week and came to pretty much the
> same patch.  But the existing "don't remove an existing address"
> behaviour looked like a design decision and I went digging to find
> exactly what ip->client->active represented - and, in particular,
> whether in could represent an address that dhclient hadn't added to
> the interface.  I did find that it could be read from the leases file
> but didn't have time to fully work through the code.
> 
> If you're happy that this patch can't incorrectly remove a pre-existing
> IP address (I'm now reasonably confident that it can't), then I'm happy
> that it otherwise works.

I think it should be fine.  It's a bit hard to infer exactly what the desired
design is from OpenBSD's dhclient code now as it uses a different tack (they
don't restart dhclient on link up, but leave the dhclient hanging around and
it restarts its own state when the link goes up).

-- 
John Baldwin
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-08-17 Thread Peter Jeremy
On 2012-Aug-17 11:48:17 -0400, John Baldwin  wrote:
>Hmm, I think I see the issue.  It doesn't export the existing lease info to
>the script when running the FAIL action.  I just tested this change and it
>removed the old IP on my laptop when I tested it just now.

I did some investigating during the week and came to pretty much the
same patch.  But the existing "don't remove an existing address"
behaviour looked like a design decision and I went digging to find
exactly what ip->client->active represented - and, in particular,
whether in could represent an address that dhclient hadn't added to
the interface.  I did find that it could be read from the leases file
but didn't have time to fully work through the code.

If you're happy that this patch can't incorrectly remove a pre-existing
IP address (I'm now reasonably confident that it can't), then I'm happy
that it otherwise works.

-- 
Peter Jeremy


pgprjxR90uyyW.pgp
Description: PGP signature


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-08-17 Thread John Baldwin
On Tuesday, August 14, 2012 8:31:51 pm Peter Jeremy wrote:
> On 2012-Jul-13 11:20:36 -0700, Yuri  wrote:
> >On 07/13/2012 02:48, Peter Jeremy wrote:
> >> This is a bug in dhclient - see PR bin/166656, which includes a fix.
> >
> >I think this PR addresses part of the problem: dhclient doesn't exit when 
> >the link goes down.
> >But even if it exits, it leaves the IP address that it has set, which is 
> >wrong. This IP address survives through the next DHCP setup process and 
ends up being the second IP address.
> >Should be very easy to on exit remove any IP address that was set during 
> >dhclient process lifetime.
> 
> I agree that it _should_ be easy to remove the existing address and the
> existing patch in that PR should already do that.  Unfortunately,
> there seems to be another issue in dhclient that means that it isn't.

Hmm, I think I see the issue.  It doesn't export the existing lease info to
the script when running the FAIL action.  I just tested this change and it
removed the old IP on my laptop when I tested it just now.  Note that I
kept the warning as "Interface foo is down" rather than "Link foo is down"
since dhclient consistently uses that language elsewhere.

Index: dhclient.c
===
--- dhclient.c  (revision 239333)
+++ dhclient.c  (working copy)
@@ -278,6 +278,11 @@ routehandler(struct protocol *p)
ifi->name);
goto die;
}
+   if (!interface_link_status(ifi->name)) {
+   warning("Interface %s is down, dhclient exiting",
+   ifi->name);
+   goto die;
+   }
break;
case RTM_IFANNOUNCE:
ifan = (struct if_announcemsghdr *)rtm;
@@ -316,6 +321,8 @@ routehandler(struct protocol *p)
 
 die:
script_init("FAIL", NULL);
+   if (ip->client->active)
+   script_write_params("old_", ip->client->active);
if (ifi->client->alias)
script_write_params("alias_", ifi->client->alias);
script_go();

-- 
John Baldwin
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-08-14 Thread Peter Jeremy
On 2012-Jul-13 11:20:36 -0700, Yuri  wrote:
>On 07/13/2012 02:48, Peter Jeremy wrote:
>> This is a bug in dhclient - see PR bin/166656, which includes a fix.
>
>I think this PR addresses part of the problem: dhclient doesn't exit when the 
>link goes down.
>But even if it exits, it leaves the IP address that it has set, which is 
>wrong. This IP address survives through the next DHCP setup process and ends 
>up being the second IP address.
>Should be very easy to on exit remove any IP address that was set during 
>dhclient process lifetime.

I agree that it _should_ be easy to remove the existing address and the
existing patch in that PR should already do that.  Unfortunately,
there seems to be another issue in dhclient that means that it isn't.

-- 
Peter Jeremy


pgp2wKcx4d2CT.pgp
Description: PGP signature


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-31 Thread Peter Jeremy
On 2012-Jul-31 09:43:00 -0400, John Baldwin  wrote:
>On Saturday, July 14, 2012 3:51:25 am Jason Hellenthal wrote:
>> 
>> On Fri, Jul 13, 2012 at 11:20:36AM -0700, Yuri wrote:
>> > But even if it exits, it leaves the IP address that it has set, which is 
>> > wrong. This IP address survives through the next DHCP setup process and 
>ends up being the second IP address.
>> > Should be very easy to on exit remove any IP address that was set during 
>> > dhclient process lifetime.
>> 
>> I couldnt agree more. Interface tear down is definately needed here.
>
>Hmmm, this does seem true.  Do you either of you have any patches for this,
>or Peter, can you extend your patch to do this?

It's not a case that I initially considered and I don't currently have
a patch for this.  I'll have a look into it.

-- 
Peter Jeremy


pgpVPl5hJPMBM.pgp
Description: PGP signature


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-31 Thread John Baldwin
On Saturday, July 14, 2012 3:51:25 am Jason Hellenthal wrote:
> 
> On Fri, Jul 13, 2012 at 11:20:36AM -0700, Yuri wrote:
> > On 07/13/2012 02:48, Peter Jeremy wrote:
> > > This is a bug in dhclient - see PR bin/166656, which includes a fix.
> > 
> > I think this PR addresses part of the problem: dhclient doesn't exit when 
> > the link goes down.
> 
> To the best of my knowledge this is the correct way to handle this. Why
> not reuse whats already been set if the link was to be brought back up
> ? ofcourse it should obviously change to the correct IP if another was
> negotiated but that is rarely the case.

The new dhclient will try to use an existing lease when it negotiates, so
I think that it should DTRT.

> > But even if it exits, it leaves the IP address that it has set, which is 
> > wrong. This IP address survives through the next DHCP setup process and 
ends up being the second IP address.
> > Should be very easy to on exit remove any IP address that was set during 
> > dhclient process lifetime.
> 
> I couldnt agree more. Interface tear down is definately needed here.

Hmmm, this does seem true.  Do you either of you have any patches for this,
or Peter, can you extend your patch to do this?

-- 
John Baldwin
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-14 Thread Jason Hellenthal


On Fri, Jul 13, 2012 at 11:20:36AM -0700, Yuri wrote:
> On 07/13/2012 02:48, Peter Jeremy wrote:
> > This is a bug in dhclient - see PR bin/166656, which includes a fix.
> 
> I think this PR addresses part of the problem: dhclient doesn't exit when the 
> link goes down.

To the best of my knowledge this is the correct way to handle this. Why
not reuse whats already been set if the link was to be brought back up
? ofcourse it should obviously change to the correct IP if another was
negotiated but that is rarely the case.

> But even if it exits, it leaves the IP address that it has set, which is 
> wrong. This IP address survives through the next DHCP setup process and ends 
> up being the second IP address.
> Should be very easy to on exit remove any IP address that was set during 
> dhclient process lifetime.

I couldnt agree more. Interface tear down is definately needed here.


-- 

 - (2^(N-1))
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-13 Thread Brooks Davis
On Fri, Jul 13, 2012 at 08:41:23AM -0400, John Baldwin wrote:
> [ Adding Brooks, IIRC, he imported the current dhclient ]
> 
> On Friday, July 13, 2012 5:48:30 am Peter Jeremy wrote:
> > On 2012-Jul-12 13:41:39 -0700, Yuri  wrote:
> > >I have the simplest possible DHCP setup: ifconfig_re0="DHCP" in 
> > >/etc/rc.conf.
> > >
> > >When the system boots, it gets connected fine.
> > >
> > >Now,  I disconnect my laptop and connect it to another network.
> > >When cable is disconnected, IP address of this interface stays the same, 
> > >old one is not removed.
> > >When I plug it into another network, the same IP address stays. New IP 
> > >doesn't get set. This is bad.
> > >So I have to manually do 'ifconfig re0 down && remove  && 
> > >ifconfig re0 up'.
> > 
> > This is a bug in dhclient - see PR bin/166656, which includes a fix.
> 
> I think this is the correct answer.  Brooks, can you look at the PR and 
> patch?  
> If you are busy I can commit it if you give the ok.

That seems fine to me.  Feel free to commit.

-- Brooks


pgpgQuilmaxO2.pgp
Description: PGP signature


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-13 Thread Yuri

On 07/13/2012 02:48, Peter Jeremy wrote:

This is a bug in dhclient - see PR bin/166656, which includes a fix.


I think this PR addresses part of the problem: dhclient doesn't exit when the 
link goes down.
But even if it exits, it leaves the IP address that it has set, which is wrong. 
This IP address survives through the next DHCP setup process and ends up being 
the second IP address.
Should be very easy to on exit remove any IP address that was set during 
dhclient process lifetime.

Yuri

___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-13 Thread John Baldwin
[ Adding Brooks, IIRC, he imported the current dhclient ]

On Friday, July 13, 2012 5:48:30 am Peter Jeremy wrote:
> On 2012-Jul-12 13:41:39 -0700, Yuri  wrote:
> >I have the simplest possible DHCP setup: ifconfig_re0="DHCP" in 
> >/etc/rc.conf.
> >
> >When the system boots, it gets connected fine.
> >
> >Now,  I disconnect my laptop and connect it to another network.
> >When cable is disconnected, IP address of this interface stays the same, 
> >old one is not removed.
> >When I plug it into another network, the same IP address stays. New IP 
> >doesn't get set. This is bad.
> >So I have to manually do 'ifconfig re0 down && remove  && 
> >ifconfig re0 up'.
> 
> This is a bug in dhclient - see PR bin/166656, which includes a fix.

I think this is the correct answer.  Brooks, can you look at the PR and patch?  
If you are busy I can commit it if you give the ok.

-- 
John Baldwin
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-13 Thread Peter Jeremy
On 2012-Jul-12 13:41:39 -0700, Yuri  wrote:
>I have the simplest possible DHCP setup: ifconfig_re0="DHCP" in 
>/etc/rc.conf.
>
>When the system boots, it gets connected fine.
>
>Now,  I disconnect my laptop and connect it to another network.
>When cable is disconnected, IP address of this interface stays the same, 
>old one is not removed.
>When I plug it into another network, the same IP address stays. New IP 
>doesn't get set. This is bad.
>So I have to manually do 'ifconfig re0 down && remove  && 
>ifconfig re0 up'.

This is a bug in dhclient - see PR bin/166656, which includes a fix.

-- 
Peter Jeremy


pgpo1p1TtzlQz.pgp
Description: PGP signature


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-13 Thread Alexander Yerenkow
>
> Add the following lines to /etc/devd.conf:
>
> notify 0 {
> match "system"  "IFNET";
> match "type""LINK_DOWN";
> media-type  "ethernet";
> action "/etc/rc.d/dhclient quietstop $subsystem; ifconfig
> $subsystem inet 0.0.0.0";
> };
>
> Then restart devd(8).
>

1. Is this rule will do nothing if interface wasn't configured as DHCP?
2. Can such primer be added (but commented) to  /etc/devd.conf in
CURRENT, so FreeBSD will be a bit more flexible for all kind of users?

-- 
Regards,
Alexander Yerenkow
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-12 Thread Kevin Lo
Yuri wrote:
> I have the simplest possible DHCP setup: ifconfig_re0="DHCP" in 
> /etc/rc.conf.
> 
> When the system boots, it gets connected fine.
> 
> Now,  I disconnect my laptop and connect it to another network.
> When cable is disconnected, IP address of this interface stays the same, 
> old one is not removed.
> When I plug it into another network, the same IP address stays. New IP 
> doesn't get set. This is bad.
> So I have to manually do 'ifconfig re0 down && remove  && 
> ifconfig re0 up'.
> 
> I believe, once interface is set as "DHCP", all those things should 
> happen automatically. dhclient should drop the old IP when cable is 
> unplugged, and should set it up anew when cable is plugged back.
> 
> Is my system misconfigured in some way, or this is the way how it works 
> in FreeBSD?

Add the following lines to /etc/devd.conf:

notify 0 {
match "system"  "IFNET";
match "type""LINK_DOWN";
media-type  "ethernet";
action "/etc/rc.d/dhclient quietstop $subsystem; ifconfig
$subsystem inet 0.0.0.0";
};

Then restart devd(8).

> Yuri

Kevin

___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-12 Thread Paul A. Procacci
On Thu, Jul 12, 2012 at 03:25:07PM -0700, Chris Benesch wrote:
> Maybe another option to dhclient to have it poll the interface every 2-3
> seconds to see if it has lost a link and if so, set the lease timer to be
> expired, and wait for it to come back and once it does, it will acquire a
> new address.
> ___
> freebsd-net@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-net
> To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"

The Operating system should generate a devd event.

Something like the following in /usr/local/etc/devd.conf should do the trick,
though I haven't tested the below with anything other than carp interfaces.
I suspect it works just the same.

##
notify 30 {
match "system" "IFNET";
match "subsystem" "em0_or_whatever";
match "type" "LINK_UP";
action "/usr/local/sbin/script_to_do_something.sh up";
};

notify 30 {
match "system" "IFNET";
match "subsystem" "em0_or_whatever";
match "type" "LINK_DOWN";
action "/usr/local/sbin/script_to_do_something.sh down";
};
##

~Paul



This message may contain confidential or privileged information. If you are not 
the intended recipient, please advise us immediately and delete this message. 
See http://www.datapipe.com/legal/email_disclaimer/ for further information on 
confidentiality and the risks of non-secure electronic communication. If you 
cannot access these links, please notify us by reply message and we will send 
the contents to you.
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-12 Thread Chris Benesch
Maybe another option to dhclient to have it poll the interface every 2-3
seconds to see if it has lost a link and if so, set the lease timer to be
expired, and wait for it to come back and once it does, it will acquire a
new address.
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-12 Thread Brian Reichert
On Thu, Jul 12, 2012 at 02:01:51PM -0700, Freddie Cash wrote:
> There's also:
> 
> service netif restart re0

Does devfs expose loss-of-link events?

If so, one would think that one could script something that watches for
link-up notifications...

(I don't know about devfs anywhere near as much as I want to.)

> -- 
> Freddie Cash
> fjwc...@gmail.com
> ___
> freebsd-net@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-net
> To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"

-- 
Brian Reichert  
BSD admin/developer at large
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-12 Thread Chris Benesch
I work with an old version of AIX all day, there are no shortcuts :(

On Thu, Jul 12, 2012 at 2:01 PM, Freddie Cash  wrote:

> On Thu, Jul 12, 2012 at 1:52 PM, Chris Benesch 
> wrote:
> > Thats pretty standard for BSD and most Unixes.  DHCP hands out leases
> for a
> > specified period of time, so unless there is a reason to reset it, it
> > wont.  Windows does that, but it is designed more as a client / user
> facing
> > OS whereas BSD is designed to run in the background silently serving you
> > content and directing traffic.
> >
> > I can save you some steps though,
> >
> > ps -ax | grep dhclient
> >
> > You will get a list, on the one that is dhclient or /sbin/dhclient, take
> > the number at the far left, thats the process ID
> >
> > kill 
> > dhclient re0
>
> pkill dhclient
> dhclient re0
>
> Saves a few more steps.  :)
>
> There's also:
>
> service netif restart re0
>
> --
> Freddie Cash
> fjwc...@gmail.com
>
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-12 Thread Freddie Cash
On Thu, Jul 12, 2012 at 1:52 PM, Chris Benesch  wrote:
> Thats pretty standard for BSD and most Unixes.  DHCP hands out leases for a
> specified period of time, so unless there is a reason to reset it, it
> wont.  Windows does that, but it is designed more as a client / user facing
> OS whereas BSD is designed to run in the background silently serving you
> content and directing traffic.
>
> I can save you some steps though,
>
> ps -ax | grep dhclient
>
> You will get a list, on the one that is dhclient or /sbin/dhclient, take
> the number at the far left, thats the process ID
>
> kill 
> dhclient re0

pkill dhclient
dhclient re0

Saves a few more steps.  :)

There's also:

service netif restart re0

-- 
Freddie Cash
fjwc...@gmail.com
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


Re: System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-12 Thread Chris Benesch
Thats pretty standard for BSD and most Unixes.  DHCP hands out leases for a
specified period of time, so unless there is a reason to reset it, it
wont.  Windows does that, but it is designed more as a client / user facing
OS whereas BSD is designed to run in the background silently serving you
content and directing traffic.

I can save you some steps though,

ps -ax | grep dhclient

You will get a list, on the one that is dhclient or /sbin/dhclient, take
the number at the far left, thats the process ID

kill 
dhclient re0

That will force it to acquire a new address.

On Thu, Jul 12, 2012 at 1:41 PM, Yuri  wrote:

> I have the simplest possible DHCP setup: ifconfig_re0="DHCP" in
> /etc/rc.conf.
>
> When the system boots, it gets connected fine.
>
> Now,  I disconnect my laptop and connect it to another network.
> When cable is disconnected, IP address of this interface stays the same,
> old one is not removed.
> When I plug it into another network, the same IP address stays. New IP
> doesn't get set. This is bad.
> So I have to manually do 'ifconfig re0 down && remove  && ifconfig
> re0 up'.
>
> I believe, once interface is set as "DHCP", all those things should happen
> automatically. dhclient should drop the old IP when cable is unplugged, and
> should set it up anew when cable is plugged back.
>
> Is my system misconfigured in some way, or this is the way how it works in
> FreeBSD?
>
> Yuri
> __**_
> freebsd-net@freebsd.org mailing list
> http://lists.freebsd.org/**mailman/listinfo/freebsd-net
> To unsubscribe, send any mail to 
> "freebsd-net-unsubscribe@**freebsd.org
> "
>
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"


System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

2012-07-12 Thread Yuri
I have the simplest possible DHCP setup: ifconfig_re0="DHCP" in 
/etc/rc.conf.


When the system boots, it gets connected fine.

Now,  I disconnect my laptop and connect it to another network.
When cable is disconnected, IP address of this interface stays the same, 
old one is not removed.
When I plug it into another network, the same IP address stays. New IP 
doesn't get set. This is bad.
So I have to manually do 'ifconfig re0 down && remove  && 
ifconfig re0 up'.


I believe, once interface is set as "DHCP", all those things should 
happen automatically. dhclient should drop the old IP when cable is 
unplugged, and should set it up anew when cable is plugged back.


Is my system misconfigured in some way, or this is the way how it works 
in FreeBSD?


Yuri
___
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"