Friday, July 27, 2018

Linux bonding example, bond multiple network interfaces into one

source: http://fibrevillage.com/sysadmin/411-linux-bonding-example-bond-multiple-network-interfaces-into-one

The Linux bonding driver provides a method for aggregating multiple network interfaces into a single logical “bonded” interface. The behavior of the bonded interfaces depends upon the mode; generally speaking, modes provide either hot standby or load balancing services. Additionally, link integrity monitoring may be performed.

peter@peter-linux-dell:~/works/src/cosmos/hostap$ modinfo bonding
filename:       /lib/modules/4.4.0-21-generic/kernel/drivers/net/bonding/bonding.ko
author:         Thomas Davis, tadavis@lbl.gov and many others
description:    Ethernet Channel Bonding Driver, v3.7.1
version:        3.7.1
license:        GPL
alias:          rtnl-link-bond
srcversion:     84775F8435FCD8AD1DB80FB
depends:     
intree:         Y
vermagic:       4.4.0-21-generic SMP mod_unload modversions

***********
example
***********



ip link add bond0 type bond mode 1 primary wlan1 miimon 100

ip link set wlan1 down
ip link set wlan1 master bond0
ip link set wlan3 down
ip link set wlan3 master bond0
ip link set bond0 up
ifconfig bond0 192.168.33.100

cat /proc/net/bonding/bond0
cat /sys/class/net/meshbond/bonding/primary
cat /sys/class/net/meshbond/bonding/slaves
cat /sys/class/net/meshbond/bonding/active_slave

* to switch primary interface
echo wlan1 > /sys/class/net/meshbond/bonding/primary
It will change active_slave too.

Thursday, June 14, 2018

backtrace in application


https://www.gnu.org/software/libc/manual/html_node/Backtraces.html
*** hostapd has good sample too

Function: int backtrace (void **buffer, int size)
Function: char ** backtrace_symbols (void *const *buffer, int size)
Function: void backtrace_symbols_fd (void *const *buffer, int size, int fd)

#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>

/* Obtain a backtrace and print it to stdout. */
void
print_trace (void)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size);
for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);
}

/* A dummy function to make the backtrace more interesting. */
void
dummy_function (void)
{
print_trace ();
}

int
main (void)
{
dummy_function ();
return 0;

}

Wednesday, May 9, 2018

Integer Constants in C language


https://download.mikroe.com/documents/compilers/mikroc/pic32/help/integer_constants.htm

Monday, May 7, 2018

upgrade firefox on ubuntu

solution 1.

sudo add-apt-repository ppa:ubuntu-mozilla-security/ppa
(sudo add-apt-repository ppa:mozillateam/firefox-next ??)

sudo apt-get update

sudo apt-get install firefox

solution 2.

Download firefox.tar.gz2
www.mozilla.com/firefox/

Extract it
tar xvjf firefox-59.0.tar.bz2


Move to /opt
Remove previous one if you have
sudo rm -rf /opt/firefox

Move the downloaded firefox directory to /opt
sudo mv firefox /opt/firefox_xx


Set up symbolic links
sudo mv /usr/bin/firefox /usr/bin/firefox-old
sudo ln -s /opt/firefox_xx/firefox /usr/bin/firefox

bash loop

run.sh
#!/bin/sh
for ((c = 1; c < 1000; c++))
do
echo "running $c times"
/root/en.sh
sleep 60
/root/run_ping.sh
done

root@LCDV2-00084:/root# cat run_ping.sh
#!/bin/sh
ping -c 5 192.168.1.121

Thursday, May 3, 2018

linux kernel tracer docs


https://www.kernel.org/doc/Documentation/trace/ftrace.txt

jiffies / time in linux kernel


https://cyberglory.wordpress.com/2011/08/21/jiffies-in-linux-kernel/

* jiffies will not be increased if timer interruption is disabled

#include <linux/time.h>

static s64 get_ns(void)
{
struct timespec ts;
getnstimeofday(&ts);
return timespec_to_ns(&ts);
}

unsigned long before, after;
unsigned int interval;

before = jiffies;
poll_wait(file, &runtime->sleep, wait);
after = jiffies;

interval = jiffies_to_usecs(after - before);

################################################

#include <linux/rtc.h>

struct timeval time;
unsigned long local_time;
 struct rtc_time tm_val;

do_gettimeofday(&time);
local_time = (u32)(time.tv_sec - (sys_tz.tz_minuteswest * 60));
rtc_time_to_tm(local_time, &tm_val);

printk(" @ (%04d-%02d-%02d %02d:%02d:%02d)\n", tm_val.tm_year + 1900, tm_val.tm_mon + 1,       tm_val.tm_mday, tm_val.tm_hour, tm_val.tm_min, tm_val.tm_sec);

################################################

struct timeval now;
struct tm tm_val;

do_gettimeofday(&now);
time_to_tm(now.tv_sec, 0, &tm_val);
printk(KERN_INFO "%d/%d %02d:%02d:%02d Days since 1 Jan: %d\n", tm_val.tm_mon + 1,
    1900 + tm_val.tm_year, tm_val.tm_hour, tm_val.tm_min,
    tm_val.tm_sec, tm_val.tm_yday);