Showing posts with label os. Show all posts
Showing posts with label os. Show all posts

Wednesday, October 18, 2017

Creating a Network Topology using VMs in VirtualBox


In my earlier posts, I covered How to - Create a Ubuntu VM in Virtualboxtopics related that and Networking for VirtualBox VMs.

In this post, I will provide steps to create the following simple network topology using VirtualBox VMs:

                     H1  <----->  R1  <----->  R2  <----->  H2

As we need only interconnectivity among the VMs, we can use "Internal Networking" mode as detailed in Networking for VirtualBox VMs. Also, I am going to leave the default NAT mode enabled VM adapters as-is. Instead, I will use the remaining VM adapters to create the above topology.
  • Right click VM H1, select "Settings", select "Network" tab, select "Adapter2", check "Enable Network Adapter", choose "Internal Network" in "Attached to". Then provide a name in "Name" field. This name & the name we provide in VM R1's Adapter should match. The VM adapters with matching names will be connected.

             

  • Right click VM R1, select "Settings", select "Network" tab, select "Adapter2", check "Enable Network Adapter", choose "Internal Network" in "Attached to". Then provide a name in "Name" field. This name & the name we provide in VM H1's Adapter should match. The VM adapters with matching names will be connected.

             

  • Now the link "H1  <----->  R1" is established.
  • Similarly, I established the other two links: "R1  <----->  R2" & "R2  <----->  H2"


Now, I booted my VMs, configured IP addresses & ran ping tests to check whether work fine. Here, I am providing screenshots of H1 & R1 VM bash terminals:
              
             


References:



Networking for VirtualBox VMs


In my earlier posts, I covered How to - Create a Ubuntu VM in Virtualbox and topics related that. In this post, I will cover basics of networking techniques for VirtualBox VMs.

Networking is necessary to connect the VM to/from internet or establish connectivity among the VMs. The following are different ways of networking (copy-pasted from https://www.virtualbox.org/manual/ch06.html#networkingmodes):

"
VirtualBox provides up to eight virtual PCI Ethernet cards for each virtual machine. We can configure only four of these form GUI. CLI allows to configure all the eight interfaces.

Each of the eight networking adapters can be separately configured to operate in one of the following modes:
Not attached
In this mode, VirtualBox reports to the guest that a network card is present, but that there is no connection -- as if no Ethernet cable was plugged into the card. This way it is possible to "pull" the virtual Ethernet cable and disrupt the connection, which can be useful to inform a guest operating system that no network connection is available and enforce a reconfiguration.
Network Address Translation (NAT)
If all you want is to browse the Web, download files and view e-mail inside the guest, then this default mode should be sufficient for you, and you can safely skip the rest of this section. Please note that there are certain limitations when using Windows file sharing (see Section 6.3.3, “NAT limitations” for details).
NAT Network
The NAT network is a new NAT flavour introduced in VirtualBox 4.3. See 6.4 for details.
Bridged networking
This is for more advanced networking needs such as network simulations and running servers in a guest. When enabled, VirtualBox connects to one of your installed network cards and exchanges network packets directly, circumventing your host operating system's network stack.
Internal networking
This can be used to create a different kind of software-based network which is visible to selected virtual machines, but not to applications running on the host or to the outside world.
Host-only networking
This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface. Instead, a virtual network interface (similar to a loopback interface) is created on the host, providing connectivity among virtual machines and the host.
Generic networking
Rarely used modes share the same generic network interface, by allowing the user to select a driver which can be included with VirtualBox or be distributed in an extension pack.
At the moment there are potentially two available sub-modes:
UDP Tunnel
This can be used to interconnect virtual machines running on different hosts directly, easily and transparently, over existing network infrastructure.
VDE (Virtual Distributed Ethernet) networking
This option can be used to connect to a Virtual Distributed Ethernet switch on a Linux or a FreeBSD host. At the moment this needs compiling VirtualBox from sources, as the Oracle packages do not include it.
The following table provides a quick overview of the most important networking modes:

Table 6.1. Overview
VM ↔ HostVM1 ↔ VM2VM → InternetVM ← Internet
Host-only++
Internal+
Bridged++++
NAT+Port forwarding
NAT Network++Port forwarding

"

After creating the VM, the default mode is NAT. So, I was able to connect to internet without any additional configuration. Select a VM & Right click, select "Settings", "Network" tab to see the VM's default networking config:
             



References:

Sunday, September 10, 2017

How to sync local repository sources from the github repository?


At times, the local sources repository could be obsolete as the gitgub repository changes after we imported. In this post, I will provide the command required to sync the local repository from the github repository.
babu@babu-VirtualBox:~/EKiD$ git pull origin master
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 3), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From https://github.com/babuneelam/EKiD
 * branch            master     -> FETCH_HEAD
   2005d11..46764be  master     -> origin/master
Updating 2005d11..46764be
Fast-forward
 .README.swp | Bin 12288 -> 0 bytes
 README      |  51 ++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 42 insertions(+), 9 deletions(-)
 delete mode 100644 .README.swp
babu@babu-VirtualBox:~/EKiD$


TBD: How are conflicts between local and remote changes handled?


Hope this helps.

Tuesday, July 28, 2015

Store and Print Stack Trace in Linux Kernel



Linux kernel has facilities to dump the stack (show_stack) from any function in kernel or kernel module. However, I haven't come across a facility that allows to store the stack trace for later retrieval and print the same. In the past, I used linux code and wrote my own function to achieve these. I will provide sample code for these facilities in this post.

Here is a sample code:

#include "asm_powerpc_stk.h" #define MAX_STK_DEPTH 30
#define STK_TRACE_SKIP_CNT 2
#ifdef CONFIG_IRQSTACKS
static __always_inline int my_valid_irq_stack(unsigned long sp, struct task_struct *p,
unsigned long nbytes)
{
unsigned long stack_page;
unsigned long cpu = task_cpu(p);
/*
* Avoid crashing if the stack has overflowed and corrupted
* task_cpu(p), which is in the thread_info struct.
*/
if (cpu < NR_CPUS && cpu_possible(cpu)) {
stack_page = (unsigned long) hardirq_ctx[cpu];
if (sp >= stack_page + sizeof(struct thread_struct)
&& sp <= stack_page + THREAD_SIZE - nbytes)
return 1;
stack_page = (unsigned long) softirq_ctx[cpu];
if (sp >= stack_page + sizeof(struct thread_struct)
&& sp <= stack_page + THREAD_SIZE - nbytes)
return 1;
}
return 0;
}
#else
#define my_valid_irq_stack(sp, p, nb) 0
#endif /* CONFIG_IRQSTACKS */
static __always_inline int my_validate_sp(unsigned long sp, struct task_struct *p,
unsigned long nbytes)
{
unsigned long stack_page = (unsigned long)task_stack_page(p);
if (sp >= (unsigned long)end_of_stack(p)
&& sp <= stack_page + THREAD_SIZE - nbytes)
return 1;
return my_valid_irq_stack(sp, p, nbytes);
}
static __always_inline unsigned int my_get_stack_trace(unsigned long *stk_trace)
{
unsigned long sp;
unsigned int i;
sp = my_get_current_stack_pointer(sp); /*Platform-specific func */
for (i=1; i< STK_TRACE_SKIP_CNT; i++)
{
if (!my_validate_sp(sp, current, STACK_FRAME_OVERHEAD))
return 0;
sp = ((unsigned long *)sp)[0];
}
for (i=0; i< MAX_STK_DEPTH; i++)
{
if (!my_validate_sp(sp, current, STACK_FRAME_OVERHEAD))
return i;
stk_trace[i] = ((unsigned long *)sp)[STACK_FRAME_LR_SAVE];
sp = ((unsigned long *)sp)[0];
}
return MAX_STK_DEPTH;
}
static void my_get_and_print_stack_trace()
{
unsigned long stk_trace[MAX_STK_DEPTH];
unsigned int stk_trace_len;
stk_trace_len = my_get_stack_trace(stk_trace);
for (k = 0; (k < stk_trace_len); k++) {
printk(" %pS\n", (void *)stk_trace[k]);
}
}
 

Here is the complete code in my git hub repository: https://github.com/babuneelam/linux_kernel_stack_trace.

Hope this helps.


References:

UA-48797665-1