Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di NA01
    Registrato dal
    May 2004
    Messaggi
    113

    [netlink]qualche problema...

    ho un semplice modulo che dovrebbe comunicare con un programmino in userspace.
    la parte di comunicazione con netlink però sembra avere serissimi problemi...
    lo ho montato prendendo spunto da un articolo online
    non so a che serva la data ready, comunque la create_socket viene chiamata al caricamento del modulo, mentre la negotiate_auth ogni qual volta che un processo apre una socket.

    il problema è che il programma che apre la socket mi va in segmentation fault...
    (sia ping o firefox o chi per lui), e dmesg si lamenta di aver trovato un puntatore nullo (però non si capisce dove e quale).
    qualcuno con più esperienza di me nell'uso di netlink mi può aiutare?

    grazie, ciao!


    codice:
    static struct sock *nl_sk = NULL;
    static u32 pid;
    static struct sk_buff *skb = NULL;
    static struct nlmsghdr *nlh = NULL;
    
    static void create_socket(){
      int err;
      nl_sk = netlink_kernel_create(NETLINK_MINOX, 1, nl_data_ready, THIS_MODULE);
      skb = skb_recv_datagram(nl_sk, 0, 0, &err);
      nlh = (struct nlmsghdr *)skb->data;
      pid = nlh->nlmsg_pid;
    }
    
    static void nl_data_ready (struct sock *sk, int len)
    {
      wake_up_interruptible(sk->sk_sleep);
    }
    
    static int negotiate_auth(u32 app_pid, int auth_type){
      char buf[MAX_PAYLOAD];
      int err;
      snprintf(buf, MAX_PAYLOAD, "%d", app_pid/*, auth_type*/);
      if(nlh != NULL && skb != NULL){
      strcpy(NLMSG_DATA(nlh), buf);
      NETLINK_CB(skb).pid = 0;
      NETLINK_CB(skb).dst_pid = pid;
      NETLINK_CB(skb).dst_group = 0;
      netlink_unicast(nl_sk, skb, pid, MSG_DONTWAIT);
      skb = skb_recv_datagram(nl_sk, 0, 0, &err);
      if(skb != NULL){
        nlh = (struct nlmsghdr *)skb->data;
        if(strcmp(NLMSG_DATA(nlh), ACCESS_PERMITTED) == 0){
          return 0;
        }
      }
      }
      return -EPERM;
    }

  2. #2
    Utente di HTML.it L'avatar di NA01
    Registrato dal
    May 2004
    Messaggi
    113

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.