Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
macchanger + WLAN + dhcpcd + openrc timing problems
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3919
Location: Hamburg

PostPosted: Fri Apr 17, 2015 12:23 pm    Post subject: macchanger + WLAN + dhcpcd + openrc timing problems Reply with quote

The config see below won't work always during boot. Sometimes I do get
Code:
[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy
 * ERROR: cannot start cupsd as net.wlp3s0 would not start
 * ERROR: cannot start dnsmasq as net.wlp3s0 would not start
 * ERROR: cannot start ntp-client as net.wlp3s0 would not start
during boot. In such a case sometimes even a "sudo /etc/init.d/net.wlp3s0 restart" won't help, so I have to reboot the (hardened) stable Gentoo. Now I do wonder, if I could run "macchanger" much more earlier in the udev - init phase ? Which udev init script I should use there to have the MAC address change already done before openrc starts the network init scripts ?
Code:
# /etc/conf.d/net
#

#  KVM
#
bridge_br0="tap0"
config_br0="192.168.1.254/16"
brctl_br0="setfd 0
sethello 10
stp off"
rc_net_br0_need="net.tap0"

config_tap0="null"
tuntap_tap0="tap"
tunctl_tap0="-u tfoerste"

#  LAN
#
config_enp0s25="null"

#   don't play well with macchanger
#
#config_wlp3s0="dhcp"

preup(){
  if [[ "$IFACE" = "wlp3s0" ]]; then
    macchanger -r $IFACE
    :
  fi
}

postup(){
  if [[ "$IFACE" = "br0" ]]; then
    sysctl -w net.ipv4.conf.br0.forwarding=1
  fi
}

predown(){
  if [[ "$IFACE" = "br0" ]]; then
    sysctl -w net.ipv4.conf.br0.forwarding=0
  fi
}

postdown(){
  if [[ "$IFACE" = "wlp3s0" ]]; then
    macchanger -p $IFACE
    :
  fi
}
filed bug #547020
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Mon Apr 20, 2015 7:14 am    Post subject: Reply with quote

This isn't a bug in the software, the error is in your preup() function which assumes the interface will be down.
Once the interface is "up", the scripts won't actually take it "down" when stopping.

Code:

preup()
{
  if [ "$IFACE" = wlp3s0 ]; then
    ifconfig "$IFACE" down
    macchanger -r "$IFACE"
    :
  fi
}

_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3919
Location: Hamburg

PostPosted: Mon Apr 20, 2015 8:47 am    Post subject: Reply with quote

UberLord wrote:
This isn't a bug in the software, the error is in your preup() function which assumes the interface will be down.
Once the interface is "up", the scripts won't actually take it "down" when stopping.

Code:

preup()
{
  if [ "$IFACE" = wlp3s0 ]; then
    ifconfig "$IFACE" down
    macchanger -r "$IFACE"
    :
  fi
}
Ah, what I already tried , was
Code:
   ifconfig "$IFACE" down
    macchanger -r "$IFACE"
 ifconfig "$IFACE" up
which won't worked right, but will try your suggestion too. That's why I filed https://bugs.gentoo.org/show_bug.cgi?id=547020
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Mon Apr 20, 2015 8:55 am    Post subject: Reply with quote

Well, if there is an error you might need a sleep between bringing the interface down and running macchanger.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 509
Location: North~Sea~Coa~s~~t~~~

PostPosted: Mon Apr 20, 2015 11:29 am    Post subject: Reply with quote

Does it make a difference, if the syntax mentioned in /usr/share/doc/netifrc-0.2.2/net.example.bz2 is used (instead of running macchanger in a `preup')?
Code:
# For changing MAC addresses using the below, emerge net-analyzer/macchanger
# - to randomize the last 3 bytes only
#mac_eth0="random-ending"
# - to randomize between the same physical type of connection (e.g. fibre,
# copper, wireless) , all vendors
#mac_eth0="random-samekind"
# - to randomize between any physical type of connection (e.g. fibre, copper,
# wireless) , all vendors
#mac_eth0="random-anykind"
# - full randomization - WARNING: some MAC addresses generated by this may NOT
# act as expected
#mac_eth0="random-full"
# custom - passes all parameters directly to net-analyzer/macchanger
#mac_eth0="some custom set of parameters"


Also it might help to separate any services related to networking, and the rest, in different runlevels:
In runlevel `default': any services that need networking + the stacked runlevel `nonetwork'
In runlevel `nonetwork': any services not networking related (including the display manager)

Then, instead of just restarting the network interface, use:
Code:
# rc nonetwork && rc default

This might solve problems with depending services.

(And if the network interfaces have their real MAC addresses put back in `nonetwork', you're able to restart Udev after an upgrade safely.)
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3919
Location: Hamburg

PostPosted: Thu Apr 23, 2015 2:05 pm    Post subject: Reply with quote

I tried :
Code:
mac_wlp3s0="random-samekind"
but got either
Code:
 * Bringing up interface wlp3s0
 *   Changing MAC address of wlp3s0 ...
RTNETLINK answers: Operation not possible due to RF-kill
 *   Failed to set MAC address                                                                                              [ !! ]
or
Code:
 * Bringing up interface wlp3s0
Current MAC:   00:1d:d7:29:0f:cd (Algolith)
Permanent MAC: e8:b1:fc:9d:87:85 (Intel Corporate)
[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy
 *   Starting wpa_supplicant on wlp3s0 ...

Tweaking /etc/init.d/net.lo is the only reliable way.

(BTW ofcourse I forgot to put xdm into "nonetwork" when I switched the fist time to
Code:
rc nonetwork
:-D)
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 509
Location: North~Sea~Coa~s~~t~~~

PostPosted: Thu Apr 23, 2015 3:27 pm    Post subject: Reply with quote

toralf wrote:
RTNETLINK answers: Operation not possible due to RF-kill

Don't know if this is good or bad news, but according to Internet this is a driver issue. The good news is, there's a kernel option: `CONFIG_RFKILL', and a userspace tool: net-wireless/rfkill. I think the driver uses rfkill on its own (to unblock the controller), but if that fails it can be scripted maybe.

In the Bluetooth wiki there are a few lines about using rfkill manually.
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3919
Location: Hamburg

PostPosted: Thu Apr 23, 2015 4:45 pm    Post subject: Reply with quote

Good hint.
But if I use "rfkill unblock 0" within preup(), then I do always just run into the subsequent issue
Code:
[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3919
Location: Hamburg

PostPosted: Fri Apr 24, 2015 12:21 pm    Post subject: Reply with quote

lost+found wrote:
Does it make a difference, if the syntax mentioned in /usr/share/doc/netifrc-0.2.2/net.example.bz2 is used (instead of running macchanger in a `preup')?
BTW, is there any chance to get the SSID coded into the config option, eg. to exclude the MAC changing at home (at least with WLAN router I eventually run into permanent connection problems, till I removed the outdated entries from the past)
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 509
Location: North~Sea~Coa~s~~t~~~

PostPosted: Sat Apr 25, 2015 7:44 am    Post subject: Reply with quote

toralf wrote:
lost+found wrote:
Does it make a difference, if the syntax mentioned in /usr/share/doc/netifrc-0.2.2/net.example.bz2 is used (instead of running macchanger in a `preup')?
BTW, is there any chance to get the SSID coded into the config option, eg. to exclude the MAC changing at home (at least with WLAN router I eventually run into permanent connection problems, till I removed the outdated entries from the past)

The easiest way, I think, is creating a parallel runlevel `home' (again with `nonetwork' stacked into it). When you switch runlevel from `default' to `nonetwork' to `home', completely different settings can be read from the file `/etc/conf.d/net.home' (/etc/conf.d/net is only used when there's no file with the runlevel name extension).

So `rc nonetwork && rc home' will then just restart everything related to the home network. To be able to switch or start a default at boot time, softlevel=home, softlevel=nonetwork etc. will work. It's possible to have separate settings for other services too (sshd?), in this wiki example. The downside is that there are much more files to maintain, and it might not work when not everything is closed down in `nonetwork' as seems to be the case... (can dhcpcd be killed?)

Maybe something like this is usefull in preup etc.:
Code:
RL=`/bin/rc-status -r`
if [ "$RL" != "home" ]; then
...
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Sat Apr 25, 2015 8:36 am    Post subject: Reply with quote

toralf wrote:
BTW, is there any chance to get the SSID coded into the config option, eg. to exclude the MAC changing at home (at least with WLAN router I eventually run into permanent connection problems, till I removed the outdated entries from the past)


No, because the interface needs to be UP to learn the SSID but down to change it.
When it's up, it's already too late - the MAC address is part of the 802.11 frames.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
vhuto
n00b
n00b


Joined: 24 Apr 2015
Posts: 2

PostPosted: Sun Apr 26, 2015 11:49 am    Post subject: Reply with quote

How are you, guys. :D

toralf wrote:
But if I use "rfkill unblock 0" within preup(),

Rfkill blocks radio emission. So, toralf, you should use "rfkill block 0" or "rfkill block wifi", etc.
Then a wireless interface will be down. At this timing, its MAC address can be changed. Maybe...

===== below is all about my Gentoo =====

I also had the same trouble with mac_wlan0="random-ending" in conf.d/net.
So, I wrote udev rule like:
Code:
SUBSYSTEM=="net", ACTION=="add",    RUN+="/usr/bin/macchanger -e %k"
SUBSYSTEM=="net", ACTION=="remove", RUN+="/usr/bin/macchanger -p %k"

This had worked for a while, but comes worse. i dont know why.

For now, using my init script:
Code:
#!/sbin/runscript

depend() {
    after udev
    before dhcpcd
}

start() {
    ebegin "Changing MAC Addresses"

    macchanger -e eno1
    macchanger -e wlo1

    eend $?
}

(Apparently it's should be rewritten with elegance :wink: )
On my Gentoo system,
- WiFi is blocked since booting system by Rfkill module setting.
- Dhcpcd daemon starts by its init script at default runrevel and provides net service.
- And I don't have complex setting about networking. (Using dhcpcd for ethernet, moreover, wpa_supplicant for wlan)
So, I have removed net.eno1 and net.wlo1 from runlevels and those settings from conf.d/net. Dhcpcd daemon takes care of those things.

Also, Dhcpcd starts wpa_supplicant daemon through its hook-script: /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant
Code:
----- /etc/dhcpcd.conf -----
#nohook wpa_supplicant
env wpa_supplicant_driver=wext
-----


Last edited by vhuto on Wed Apr 29, 2015 9:33 am; edited 1 time in total
Back to top
View user's profile Send private message
Doron
n00b
n00b


Joined: 28 Sep 2006
Posts: 48

PostPosted: Mon Apr 27, 2015 2:11 pm    Post subject: Reply with quote

I may be able to help, since I had similar issues and after some debugging managed to
find the issue;

Currently I have installed:
[I] net-analyzer/macchanger
Available versions: 1.7.0

It seems that since 1.6.0 (yes..) the output of macchanger changed.
so net-misc/netifrc-0.2.2 was looking for the wrong string....

You can see it all in: https://bugs.gentoo.org/show_bug.cgi?id=504458 (which I found after digging the code for too long).

Bottom line, you should use net-misc/netifrc-0.2.3 by adding a keyword to it
and use the standard way in the conf file:

#mac_eth0="random-anykind"
_________________
Common sense is not so common. (Voltaire)
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3919
Location: Hamburg

PostPosted: Mon Apr 27, 2015 2:29 pm    Post subject: Reply with quote

Ah - thx Doron !
FWIW I field a now bug :https://bugs.gentoo.org/show_bug.cgi?id=547906 for it
Back to top
View user's profile Send private message
vhuto
n00b
n00b


Joined: 24 Apr 2015
Posts: 2

PostPosted: Wed Apr 29, 2015 9:51 am    Post subject: Reply with quote

Oh, 0.2.3, 0.2.3...let me try it.

I restored the netifrc standard way. It successfully changes MAC address.
(The code config_interface="dhcp" dosen't work, so I added a dhcpcd service in boot runlevel.)
WiFi connection is eventually not established. I need restart of wpa_supplicant for it.
Code:
wpa_cli terminate
wpa_supplicant -iwlo1 -Dwext -c/etc/wpa_supplicant/wpa_supplicant.conf -B

Also on my environment above, I need this restart every time after changing MAC address. Perhaps my customizing is odd a bit :?:

Anyway sorry for noise. Congrats :P
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum