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



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


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