4949struct tipc_nl_compat_msg {
5050 u16 cmd ;
5151 int rep_size ;
52+ int req_type ;
5253 struct sk_buff * rep ;
5354 struct tlv_desc * req ;
5455 struct sock * dst_sk ;
@@ -59,6 +60,11 @@ struct tipc_nl_compat_cmd_dump {
5960 int (* format )(struct tipc_nl_compat_msg * msg , struct nlattr * * attrs );
6061};
6162
63+ struct tipc_nl_compat_cmd_doit {
64+ int (* doit )(struct sk_buff * skb , struct genl_info * info );
65+ int (* transcode )(struct sk_buff * skb , struct tipc_nl_compat_msg * msg );
66+ };
67+
6268static int tipc_skb_tailroom (struct sk_buff * skb )
6369{
6470 int tailroom ;
@@ -213,6 +219,78 @@ static int tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
213219 return err ;
214220}
215221
222+ static int __tipc_nl_compat_doit (struct tipc_nl_compat_cmd_doit * cmd ,
223+ struct tipc_nl_compat_msg * msg )
224+ {
225+ int err ;
226+ struct sk_buff * doit_buf ;
227+ struct sk_buff * trans_buf ;
228+ struct nlattr * * attrbuf ;
229+ struct genl_info info ;
230+
231+ trans_buf = alloc_skb (NLMSG_GOODSIZE , GFP_KERNEL );
232+ if (!trans_buf )
233+ return - ENOMEM ;
234+
235+ err = (* cmd -> transcode )(trans_buf , msg );
236+ if (err )
237+ goto trans_out ;
238+
239+ attrbuf = kmalloc ((tipc_genl_family .maxattr + 1 ) *
240+ sizeof (struct nlattr * ), GFP_KERNEL );
241+ if (!attrbuf ) {
242+ err = - ENOMEM ;
243+ goto trans_out ;
244+ }
245+
246+ err = nla_parse (attrbuf , tipc_genl_family .maxattr ,
247+ (const struct nlattr * )trans_buf -> data ,
248+ trans_buf -> len , NULL );
249+ if (err )
250+ goto parse_out ;
251+
252+ doit_buf = alloc_skb (NLMSG_GOODSIZE , GFP_KERNEL );
253+ if (!doit_buf ) {
254+ err = - ENOMEM ;
255+ goto parse_out ;
256+ }
257+
258+ doit_buf -> sk = msg -> dst_sk ;
259+
260+ memset (& info , 0 , sizeof (info ));
261+ info .attrs = attrbuf ;
262+
263+ err = (* cmd -> doit )(doit_buf , & info );
264+
265+ kfree_skb (doit_buf );
266+ parse_out :
267+ kfree (attrbuf );
268+ trans_out :
269+ kfree_skb (trans_buf );
270+
271+ return err ;
272+ }
273+
274+ static int tipc_nl_compat_doit (struct tipc_nl_compat_cmd_doit * cmd ,
275+ struct tipc_nl_compat_msg * msg )
276+ {
277+ int err ;
278+
279+ if (msg -> req_type && !TLV_CHECK_TYPE (msg -> req , msg -> req_type ))
280+ return - EINVAL ;
281+
282+ err = __tipc_nl_compat_doit (cmd , msg );
283+ if (err )
284+ return err ;
285+
286+ /* The legacy API considered an empty message a success message */
287+ msg -> rep = tipc_tlv_alloc (0 );
288+ if (!msg -> rep )
289+ return - ENOMEM ;
290+
291+ return 0 ;
292+ }
293+
216294static int tipc_nl_compat_bearer_dump (struct tipc_nl_compat_msg * msg ,
217295 struct nlattr * * attrs )
218296{
@@ -226,18 +304,82 @@ static int tipc_nl_compat_bearer_dump(struct tipc_nl_compat_msg *msg,
226304 nla_len (bearer [TIPC_NLA_BEARER_NAME ]));
227305}
228306
307+ static int tipc_nl_compat_bearer_enable (struct sk_buff * skb ,
308+ struct tipc_nl_compat_msg * msg )
309+ {
310+ struct nlattr * prop ;
311+ struct nlattr * bearer ;
312+ struct tipc_bearer_config * b ;
313+
314+ b = (struct tipc_bearer_config * )TLV_DATA (msg -> req );
315+
316+ bearer = nla_nest_start (skb , TIPC_NLA_BEARER );
317+ if (!bearer )
318+ return - EMSGSIZE ;
319+
320+ if (nla_put_string (skb , TIPC_NLA_BEARER_NAME , b -> name ))
321+ return - EMSGSIZE ;
322+
323+ if (nla_put_u32 (skb , TIPC_NLA_BEARER_DOMAIN , ntohl (b -> disc_domain )))
324+ return - EMSGSIZE ;
325+
326+ if (ntohl (b -> priority ) <= TIPC_MAX_LINK_PRI ) {
327+ prop = nla_nest_start (skb , TIPC_NLA_BEARER_PROP );
328+ if (!prop )
329+ return - EMSGSIZE ;
330+ if (nla_put_u32 (skb , TIPC_NLA_PROP_PRIO , ntohl (b -> priority )))
331+ return - EMSGSIZE ;
332+ nla_nest_end (skb , prop );
333+ }
334+ nla_nest_end (skb , bearer );
335+
336+ return 0 ;
337+ }
338+
339+ static int tipc_nl_compat_bearer_disable (struct sk_buff * skb ,
340+ struct tipc_nl_compat_msg * msg )
341+ {
342+ char * name ;
343+ struct nlattr * bearer ;
344+
345+ name = (char * )TLV_DATA (msg -> req );
346+
347+ bearer = nla_nest_start (skb , TIPC_NLA_BEARER );
348+ if (!bearer )
349+ return - EMSGSIZE ;
350+
351+ if (nla_put_string (skb , TIPC_NLA_BEARER_NAME , name ))
352+ return - EMSGSIZE ;
353+
354+ nla_nest_end (skb , bearer );
355+
356+ return 0 ;
357+ }
358+
229359static int tipc_nl_compat_handle (struct tipc_nl_compat_msg * msg )
230360{
231361 struct tipc_nl_compat_cmd_dump dump ;
362+ struct tipc_nl_compat_cmd_doit doit ;
232363
233364 memset (& dump , 0 , sizeof (dump ));
365+ memset (& doit , 0 , sizeof (doit ));
234366
235367 switch (msg -> cmd ) {
236368 case TIPC_CMD_GET_BEARER_NAMES :
237369 msg -> rep_size = MAX_BEARERS * TLV_SPACE (TIPC_MAX_BEARER_NAME );
238370 dump .dumpit = tipc_nl_bearer_dump ;
239371 dump .format = tipc_nl_compat_bearer_dump ;
240372 return tipc_nl_compat_dumpit (& dump , msg );
373+ case TIPC_CMD_ENABLE_BEARER :
374+ msg -> req_type = TIPC_TLV_BEARER_CONFIG ;
375+ doit .doit = tipc_nl_bearer_enable ;
376+ doit .transcode = tipc_nl_compat_bearer_enable ;
377+ return tipc_nl_compat_doit (& doit , msg );
378+ case TIPC_CMD_DISABLE_BEARER :
379+ msg -> req_type = TIPC_TLV_BEARER_NAME ;
380+ doit .doit = tipc_nl_bearer_disable ;
381+ doit .transcode = tipc_nl_compat_bearer_disable ;
382+ return tipc_nl_compat_doit (& doit , msg );
241383 }
242384
243385 return - EOPNOTSUPP ;
@@ -335,6 +477,8 @@ static int tipc_nl_compat_tmp_wrap(struct sk_buff *skb, struct genl_info *info)
335477
336478 switch (req -> cmd ) {
337479 case TIPC_CMD_GET_BEARER_NAMES :
480+ case TIPC_CMD_ENABLE_BEARER :
481+ case TIPC_CMD_DISABLE_BEARER :
338482 return tipc_nl_compat_recv (skb , info );
339483 }
340484
0 commit comments