[Libct] ***SPAM*** Re: Regarding network namespaces.
Andrew Vagin
avagin at gmail.com
Fri Jan 30 10:55:16 PST 2015
On Thu, Jan 29, 2015 at 05:56:33PM +0000, Monali Porob wrote:
> Hi Andrew ,
>
> While trying things with network namespaces , I tried to use the
> libct_net_dev_add_ip_addr() in the test/ct_net_veth.c and found the callback
> is not getting spawned.
>
> The test program exits with main:89: FAIL: CT is not alive . How should I use
> this api . I am assuming that the api can be used to set the IP address for the
> veth0 inside the namespace. Correct me here if that’s not the case.
>
> I have limited background of libnl.
>
>
>
> I did try executing shell commands like ifconfig and setting up ip addresses on
> veth pairs. With this I could get the namespace communication set to the
> outside world using Routes .
>
> I was wondering if libct APIs could be used to do the same . Hence tried using
> libct_net_dev_add_ip_addr(). Please suggest .
>
>
>
> Thanks and Regards,
>
> Monali
>
>
>
> Changed ct_net_veth.c
>
> int main(int argc, char **argv)
>
> {
>
> int p[2];
>
> struct ct_arg ca;
>
> libct_session_t s;
>
> ct_handler_t ct;
>
> ct_process_desc_t pd;
>
> ct_process_t pr;
>
> struct ct_net_veth_arg va;
>
> ct_net_t nd;
>
>
>
> ca.mark = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
>
> MAP_SHARED | MAP_ANON, 0, 0);
>
> pipe(p);
>
>
>
> ca.mark[0] = 0;
>
> ca.mark[1] = 0;
>
> ca.mark[2] = 0;
>
> ca.wait_pipe = p[0];
>
>
>
> va.host_name = VETH_HOST_NAME;
>
> va.ct_name = VETH_CT_NAME;
>
>
>
> s = libct_session_open_local();
>
> ct = libct_container_create(s, "test");
>
> pd = libct_process_desc_create(s);
>
> libct_container_set_nsmask(ct, CLONE_NEWNET);
>
>
>
> nd = libct_net_add(ct, CT_NET_VETH, &va);
>
> if (libct_handle_is_err(nd))
>
> return tst_err("Can't add hostnic");
>
>
>
> if (libct_net_dev_set_mac_addr(nd, "00:11:22:33:44:55"))
>
> return tst_err("Can't set mac");
>
>
>
> //Added by Monali
>
> if (libct_net_dev_add_ip_addr(nd, "VETH_CT_ADDR"))
I think here is a mistake. You need to remove double quotes arount
VETH_CT_ADDR.
You need smth like this:
#define VETH_CT_ADDR "192.168.87.123/24"
...
if (libct_net_dev_add_ip_addr(nd, VETH_CT_ADDR))
Here is an example
https://github.com/avagin/libct/blob/veth-test/test/ct_net_veth.c
Thanks,
Andrew
>
> return tst_err("Can't set addr");
>
>
>
> pr = libct_container_spawn_cb(ct, pd, check_ct_net, &ca);
>
> if (libct_handle_is_err(pr))
>
> return tst_err("Can't spawn CT");
>
>
>
> …Same as in git
>
>
>
> }
>
> _______________________________________________
> Libct mailing list
> Libct at openvz.org
> https://lists.openvz.org/mailman/listinfo/libct
More information about the Libct
mailing list