Re: How to add pppoe connection in NM plug-in



On Mon, May 3, 2010 at 5:32 AM, Dan Williams <dcbw redhat com> wrote:
> On Fri, 2010-04-30 at 21:04 +0800, Mu Qiao wrote:
>> On Tue, Apr 27, 2010 at 1:29 PM, Mu Qiao <qiaomuf gmail com> wrote:
>> > On Tue, Apr 27, 2010 at 8:15 AM, Mu Qiao <qiaomuf gmail com> wrote:
>> >> On Tue, Apr 27, 2010 at 7:18 AM, Dan Williams <dcbw redhat com> wrote:
>> >>> On Mon, 2010-04-26 at 21:04 +0800, Mu Qiao wrote:
>> >>>> Hi dear Dan and all,
>> >>>> I've tried to find how to add pppoe connection in NM plug-in. But I
>> >>>> didn't find any example in existing plugin source code. Is there
>> >>>> anything I missed?
>> >>>
>> >>> The connection editor does add PPPoE.  Note that until we fix a few
>> >>> things, PPPoE is only available on Ethernet (ie wired) devices, not yet
>> >>> on wifi.  Making that work is fairly high on the to-do list.
>> >>>
>> >>>> Then I tried to write code in the way similar as adding a
>> >>>> wired_connection_setting as following:
>> >>>>
>> >>>>         NMSettingPPPOE *s_pppoe;
>> >>>>         gchar *value;
>> >>>>         s_pppoe = NM_SETTING_PPPOE(nm_setting_pppoe_new());
>> >>>>         //NM_SETTING_PPPOE_SERVICE NM_SETTING_PPPOE_USERNAME
>> >>>> NM_SETTING_PPPOE_PASSWORD
>> >>>>         value = ifnet_getdata(block, "username");
>> >>>>         if (!value) {
>> >>>>                 g_set_error(error, ifnet_plugin_error_quark(), 0,
>> >>>>                             "ppp requires at lease a username");
>> >>>>                 return;
>> >>>>         }
>> >>>>         g_object_set(s_pppoe, NM_SETTING_PPPOE_USERNAME, value, NULL);
>> >>>>         value = ifnet_getdata(block, "password");
>> >>>>         if (!value) {
>> >>>>                 value="";
>> >>>>         }
>> >>>>         g_object_set(s_pppoe, NM_SETTING_PPPOE_PASSWORD, value, NULL);
>> >>>>         nm_connection_add_setting(connection, NM_SETTING(s_pppoe));
>> >>>>
>> >>>> Am I doing in the right way? Is there any other thing I should take
>> >>>> care of? Could please give me some direction.
>> >>>
>> >>> That looks mostly right, actually.  But make sure to set the
>> >>> NMSettingConnection's 'type' property to NM_SETTING_PPPOE_SETTING_NAME.
>> >>>
>> >>> Try calling "nm_connection_verify()" on your final connection at some
>> >>> point.  Does that return TRUE or FALSE, and if FALSE, what is the error
>> >>> that it returns?
>> >>>
>> >>> Dan
>> >>>
>> >>>
>> >>>
>> >>
>> >> I set that property by:
>> >> g_object_set(setting,
>> >>                     NM_SETTING_CONNECTION_TYPE, type,
>> >>                     NM_SETTING_CONNECTION_ID, idstr,
>> >>                     NM_SETTING_CONNECTION_UUID, uuid,
>> >>                     NM_SETTING_CONNECTION_READ_ONLY, TRUE,
>> >>                     NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL);
>> >> (type is NM_SETTING_PPPOE_SETTING_NAME)
>> >>
>> >> During setting building, there was no error detected. When I called
>> >> nm_connection_verify(), it returned FALSE. I printed the error by:
>> >> if (error && *error)
>> >>                PLUGIN_PRINT("SCPlugin-Ifnet",
>> >>                             "Found error: %s", (*error)->message);
>> >>
>> >> in /var/log/messages, the code above generated one line:
>> >> SCPlugin-Ifnet: Found error: (null)
>> >>
>> >>
>> >> To sum up the connection building code I've written:
>> >> nm_connection_add_setting(connection, NM_SETTING(setting));
>> >> g_object_set(setting,
>> >>                     NM_SETTING_CONNECTION_TYPE, type,
>> >>                     NM_SETTING_CONNECTION_ID, idstr,
>> >>                     NM_SETTING_CONNECTION_UUID, uuid,
>> >>                     NM_SETTING_CONNECTION_READ_ONLY, TRUE,
>> >>                     NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL);
>> >>
>> >> g_object_set(s_pppoe, NM_SETTING_PPPOE_USERNAME, value, NULL);
>> >> g_object_set(s_pppoe, NM_SETTING_PPPOE_PASSWORD, value, NULL);
>> >> nm_connection_add_setting(connection, NM_SETTING(s_pppoe));
>> >> g_object_set(ip4_setting,
>> >>                             NM_SETTING_IP4_CONFIG_METHOD,
>> >>                             NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
>> >> nm_connection_add_setting(connection, NM_SETTING(ip4_setting));
>> >> success = nm_connection_verify(connection, error);
>> >> if (error && *error)
>> >>                PLUGIN_PRINT("SCPlugin-Ifnet",
>> >>                             "Found error: %s", (*error)->message);
>> >> --
>> >> Best wishes,
>> >> Mu Qiao
>> >>
>> > I find how to make pppoe setting in ifcfg-rh/tests/test-ifcfg-rh.c.
>> > test_write_wired_pppoe() showed me the code.
>> > I think I missed ppp setting so that it could't pass the
>> > nm_connection_verify() method.
>> >
>> > I also find that NM_SETTING_WIRED_SETTING_NAME is used for pppoe
>> > connection in that method. I changed it to
>> > NM_SETTING_PPPOE_SETTING_NAME.
>> >
>> > Now the connection could pass the nm_connection_verify() method. I
>> > will test it when I get a pppoe network environment.
>> >
>> > --
>> > Best wishes,
>> > Mu Qiao
>> >
>>
>> Hi Dan,
>> I've tried to make a pppoe connection by the plugin but still I can't
>> get it to work.
>> The connection could be verified valid, however, I find ppp-manager
>> would not be started in this way.
>> I've read some source code on how to manually start ppp-manager but I
>> find it's hard because I can't get a NMManager object. Then I can't
>> get a device list and can't create NMActRequest to start ppp-manager.
>> Am I doing this in the right way? Is the plugin able to manage pppoe
>> connection? If it can, could please give me some direction on how to
>> make the implementation?
>
> Hmm, do you have NM logs of trying to tell NM to activate that PPPoE
> connection that I could see? There could be some errors there.  With
> latest git you can also use the new logging stuff to get more debug
> information; use --log-level=debug on the NM command line to get a ton
> of spew that could be helpful.
>
> Dan
>
>
>

I've made a mistake on setting connection type :P. Now the ppp manager
could be automatically started.

Here is a strange thing. The pppoe connection will failed to be
established at NM startup. However, when I modify configuration file
to force the connection setting being reloaded(the GFileMonitor works
here), the connection will successfully be established. Actually, I
didn't make any change except for adding a blank line to the
configuration file. The same code is used for both situation.
I've tried to get more log using latest git version of NM. But it
seems that this version won't work well on my machine. I'll try to
figure out why.
So the following log is generated by current stable version of NM, I
don't know what the state number or reason number stands for.
Failed To Establish:

pppd[15206]: Plugin rp-pppoe.so loaded.
pppd[15206]: RP-PPPoE plugin version 3.3 compiled against pppd 2.4.4
pppd[15206]: Plugin /usr/lib64/pppd/2.4.4/nm-pppd-plugin.so loaded.
pppd[15206]: pppd 2.4.4 started by root, uid 0
pppd[15206]: PPP session is 16355
pppd[15206]: Using interface ppp0
pppd[15206]: Connect: ppp0 <--> eth0
NetworkManager: <info>  (eth0): device state change: 7 -> 9 (reason 7)
NetworkManager: <info>  Marking connection 'system connection (ppp0)' invalid.
NetworkManager: <info>  Activation (eth0) failed.
NetworkManager: <info>  (eth0): device state change: 9 -> 3 (reason 0)
NetworkManager: <info>  (eth0): deactivating device (reason: 0).
NetworkManager: <debug> [1272860110.000913] ensure_killed(): waiting
for ppp pid 15206 to exit
NetworkManager: <debug> [1272860110.010935] ensure_killed(): ppp pid
15206 cleaned up

Successfully established after configuration reloaded

pppd[15211]: Plugin rp-pppoe.so loaded.
pppd[15211]: RP-PPPoE plugin version 3.3 compiled against pppd 2.4.4
pppd[15211]: Plugin /usr/lib64/pppd/2.4.4/nm-pppd-plugin.so loaded.
pppd[15211]: pppd 2.4.4 started by root, uid 0
pppd[15211]: PPP session is 16355
pppd[15211]: Using interface ppp0
pppd[15211]: Connect: ppp0 <--> eth0
pppd[15211]: Remote message: Authentication success,Welcome!
pppd[15211]: PAP authentication succeeded
pppd[15211]: peer from calling number 00:18:82:87:F9:B3 authorized
pppd[15211]: local  IP address 117.33.40.161
pppd[15211]: remote IP address 117.33.32.1
pppd[15211]: primary   DNS address 61.134.1.5
pppd[15211]: secondary DNS address 218.30.19.50
NetworkManager: <info>  PPP manager(IP Config Get) reply received.
NetworkManager: <info>  Activation (eth0) Stage 4 of 5 (IP4 Configure
Get) scheduled...
NetworkManager: <info>  Activation (eth0) Stage 4 of 5 (IP4 Configure
Get) started...
NetworkManager: <info>  Activation (eth0) Stage 5 of 5 (IP Configure
Commit) scheduled...
NetworkManager: <info>  Activation (eth0) Stage 4 of 5 (IP4 Configure
Get) complete.
NetworkManager: <info>  Activation (eth0) Stage 5 of 5 (IP Configure
Commit) started...
NetworkManager: <info>  Clearing nscd hosts cache.
NetworkManager: <info>  (eth0): device state change: 7 -> 8 (reason 0)
NetworkManager: <info>  Clearing nscd hosts cache.
NetworkManager: <info>  Policy set 'system connection (ppp0)' (ppp0)
as default for routing and DNS.
NetworkManager: <info>  Activation (eth0) successful, device activated.
NetworkManager: <info>  Activation (eth0) Stage 5 of 5 (IP Configure
Commit) complete.

Here is the code snippet for reloading connections:

                exported = nm_ifnet_connection_new(conn_name);
                old = g_hash_table_lookup(priv->config_connections, conn_name);
                if (old && exported) {

nm_sysconfig_connection_update(NM_SYSCONFIG_CONNECTION(old),
                                            NM_CONNECTION(exported), TRUE,
                                            NULL)  // return value is TRUE
                } else if (exported) {
                        g_hash_table_insert(priv->config_connections,
                                            g_strdup(conn_name), exported);
                }


-- 
Best wishes,
Mu Qiao
GnuPG fingerprint: 92B1 B0C4 8D14 F8C4 EFA5  3ACC 30B3 0DE4 17B1 57E9


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]